huy/qclog

一个允许您更灵活使用monolog的包。

dev-master 2016-05-23 08:34 UTC

This package is not auto-updated.

Last update: 2024-09-23 12:03:19 UTC


README

Monolog简单封装,可以方便地指定日志输出格式和日志路径。

用法

qclog.php复制到app\config目录下,默认配置如下:

<?php

return [
  
  'dateFormat' => "Y-m-d H:i:s",  //时间格式
  'outputFormat' => "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n", //日志格式

  'userLog' => [
    //'file' => '/var/log/php/user.log',
    'dateFormat' => 'Y n j, g:i a'
  ],

  'goodsLog' => [
    'file' => '/var/log/php/goods.log'
  ],
  
];

'dateFormat'和'outputFormat'指定时间格式和日志输出格式。
'userLog'和'goodsLog'中配置的'dateFormat'和'outputFormat'会覆盖外层配置。 'file'配置日志输出的文件。

然后可以这样使用:

use Qc\QcLog;

QcLog::userLog()->addInfo('hello');
QcLog::goodsLog()->addWarning('this goods is missing');
QcLog::addInfo('this message will be wirtten in storage/logs/laravel.log');

类似addInfo的方法有: 'addInfo', 'addDebug', 'addNotice', 'addWarning','addEmergency', 'addAlert', 'addCritical', 'addError'

这些都是monolog的基础方法。