huy/qclog

A package that allows you to use monolog more flexibly.

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简单封装,可以方便的指定日志输出格式和日志路径。

usage

拷贝qclog.phpapp\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基础方法。