Answer the question
In order to leave comments, you need to log in
Why is YII not writing data to log?
The application has console commands that work. I want to write a log when using them. In the config file console.php added a Goal with the category produceStatisticByDay.
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning',],
],
[
'class' => 'yii\log\FileTarget',
'logFile' => '@runtime/logs/produceStatisticByDay.log',
'levels' => ['info'],
'categories' => ['produceStatisticByDay'],
]
],
],
public function actionPartnerProduceStatistic($partnerID, $startDate, $endDate = null)
{
$format = ' Загружаем статистику по товарам для партнёра %d от %s %s ' . "\n";
echo sprintf($format, $partnerID, $startDate, $endDate != null ? 'до ' . $endDate : null);
Yii::info('produce log', 'produceStatisticByDay');
Yii::info('app log');
Yii::getLogger()->log('produce log via log', 0 , 'produceStatisticByDay');
Yii::getLogger()->log('app log via log',0 );
(new BackStatLoadingService())->createProduceStatForPartner($partnerID, $startDate, $endDate);
return ExitCode::OK;
}
Answer the question
In order to leave comments, you need to log in
The solution turned out to be much simpler, the application did not have enough rights on the server. After adding the rights everything worked like clockwork
1. Check if the component is listed in the bootstrap preload
2. Try setting the target to flushInterval and exportInterval to 1, for example:
'log' => [
'flushInterval' => 1,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'exportInterval' => 1,
],
],
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question