S
S
SalaDIN_912020-03-05 14:05:11
Yii
SalaDIN_91, 2020-03-05 14:05:11

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'],
                ]
            ],
        ],

I call both by the application and through the logger, but the result is 0. What could be the error?
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

2 answer(s)
S
SalaDIN_91, 2020-04-15
@SalaDIN_91

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

E
Evgeny Musonov, 2020-03-06
@evmusonov

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 question

Ask a Question

731 491 924 answers to any question