Yii2 Log Helper
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);
}
}
}
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' => []
]
],
],
// ...
],
];
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,
]
],
],
],
];