rowasc/yii2loggingutils

一个非常基础的日志工具类。设计为特质(trait)使用,以便根据您所在的类使用默认的类别。

安装: 18

依赖: 1

建议: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 1

类型:yii2-extension

1.0.1 2015-09-05 23:12 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:28:03 UTC


README

一个非常基础的日志工具,帮助从使用此特质的控制器中设置日志类别。

使用方法

##配置

在您的Yii2应用程序配置中,在components=>log下设置您想要使用的新日志类别

'components' =>[
'log' => [
    'traceLevel' => YII_DEBUG ? 3 : 0,
    'targets' => [
        [
            'class' => 'yii\log\FileTarget',
            'levels' => ['info', 'error', 'warning', 'trace'],
            'categories' => ['myawesomecategory'],
            'logFile' => '@app/runtime/logs/myawesomecategory.log',
            'maxFileSize' => 2048,
            'maxLogFiles' => 10,
            'logVars' => []
        ]

为每个类定义默认的日志类别,这样当出现问题时,您就有明确的类别可以查找。

namespace your\own\namespace;
use rowasc\components\Log;
class YourClass extends AnyClass {
    use Log;
    public $log_category="categoryOfYourLog";
    public function yourFancyFunction(){
        /** now use some loggers ! **/
        $this->_logError("Error that you really want to log " );
        $this->_logTrace($e);
    
    }
}

如果您想要为某些消息使用不同的类别,只需在调用日志函数时覆盖类别即可。

namespace your\own\namespace;
use rowasc\components\Log;
class YourClass extends AnyClass {
    use Log;
    public $log_category="categoryOfYourLog";
    public function yourFancyFunction(){
        /** now use some loggers ! **/
        $this->_logError("Error that you really want to log " ,"myawesomecategory");
        $this->_logTrace($e,"myerrorcategory");
    
    }
}