rowasc / yii2loggingutils
A very basic logging utility class. Designed to be used as a trait so you can use a default category depending on the class you are at .
Installs: 18
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
Type:yii2-extension
Requires
- yiisoft/yii2: @stable
Requires (Dev)
- codeception/codeception: ^2.1@dev
- yiisoft/yii2-codeception: ^2.0@dev
This package is not auto-updated.
Last update: 2025-05-10 21:51:11 UTC
README
A very basic logging utility to help setup log categories from the controllers that "use" this trait/
Usage
##Configuration
In your Yii2's application config, under components=>log setup new logging categories you want to use
'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' => [] ]
Define your default log category for each class, so you have well defined categories to look into when something goes wrong.
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); } }
If you want to have a different category for some messages, just override the category when calling the logging functions.
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"); } }