prowebcraft / yii2-log-helper
Base helper class for better logging experience. Send messages to telegram
Installs: 1 218
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
pkg:composer/prowebcraft/yii2-log-helper
Requires
- php: >=7.4.0
- yiisoft/yii2-httpclient: ~2.0
This package is auto-updated.
Last update: 2025-10-11 12:47:57 UTC
README
Yii2 Log Helper
General usage
Attach \prowebcraft\yii2log\trait\Log trait to your class or extend it from \prowebcraft\yii2log\Log
Call static debug, info, warning or error method to log some info, for example:
<?php use \prowebcraft\yii2log\trait\Log; class MarsExpedition { use Log; public function doHeavyJob(){ self::info('Prepare to launch'); $missionInfo = [ 'title' => 'Mission to Mars', 'distance' => '54.6m km', 'pilot' => 'Elon Musk', ]; self::debug('Flight data: %s', $missionInfo); try { // mission inpossible } catch($e) { self::error('Error flying to Mars: %s', $e); } } }
Configuration
Send messages to telegram
To send error/warning messages to telegram add component and log target to your config (ex. common/main-local.php):
'components' => [ // ... 'telegram' => [ 'class' => \prowebcraft\yii2log\TelegramBot::class, 'token' => '123:xyz' // telegram bot token, 'defaultChatId' => -1000000000, // group or channel id, 'targetPerCategory' => [ 'mission_control' => -20000000 ], ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => \prowebcraft\yii2log\TelegramTarget::class, 'levels' => ['error', 'warning'], // log levels 'logVars' => [] ] ], ], // ... ], ];
Output messages to console
To output messages to console in Console applications log target to your config (ex. console/main-local.php):
'components' => [, 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'flushInterval' => 1, 'targets' => [ [ 'class' => \prowebcraft\yii2log\ConsoleTarget::class, 'levels' => ['error', 'warning', 'info', 'trace'], 'logVars' => [], 'displayCategory' => true, 'except' => [ 'yii\*' ], 'exportInterval' => 1, ] ], ], ], ];