limingxinleo/x-phalcon-logger

Phalcon Logger 工厂类

1.0.4 2018-04-24 04:00 UTC

This package is auto-updated.

Last update: 2024-10-17 19:43:23 UTC


README

Build Status

安装

composer require limingxinleo/x-phalcon-logger

使用

<?php

use Xin\Phalcon\Logger\Factory;
use Phalcon\Config;
use Phalcon\Logger\Formatter\Line;
use Xin\Phalcon\Logger\Sys;

// 初始化工厂
$config = new Config([
    'application' => [
        'logDir' => __DIR__ . '/../logs/',
    ],
]);

$factory = new Factory($config);

$context = [
    'dir' => 'test' // 如果不设置子目录,则根据日期分目录
];

// 获取单例日志实例
$logger = $factory->getLogger('info', Sys::LOG_ADAPTER_FILE, $context);
// 设置格式化
$formatter = new Line("[%date%][%type%] %message%", "Y-m-d H:i:s");
$logger->setFormatter($formatter);

// 写入日志
$logger->info('日志数据');