-1

Im looking for a log system which works with different verbosity levels and flushes to file or console immediately. I work with yii2. They Yii2 Log is good and has info, debug, warn, error levels. But I cannot get it to work realtime to flush on screen. I have tried with flushInterval as 1 or even 0 but does not work. yii2 log methods have application param, so I can filter what parts get logged, in case some module is buggy. Many of my cli apps never die, so logs come up only after many hours like a flood.

Maybe there is a totally diff composer package which does same thing.

Thanks.

thevikas
  • 1,618
  • 1
  • 14
  • 31

1 Answers1

0

Logs are grouped on two levels:

  1. Dispatcher level controlled by Dispatcher::$flushInterval.
  2. Log target level controlled by Target::$exportInterval.

So in addition to flushInterval, you need to also configure exportInterval for given target, if you want to export every single log one by one:

'log' => [
    'flushInterval' => 1,
    'targets' => [
        'file' => [
            'class' => yii\log\FileTarget::class,
            'exportInterval' => 1,
            'levels' => ['trace', 'info'],
        ],
    ],
],

But you may get better performance by calling Yii::$app->log->flush(true) after finishing every task on long-running process. So if you're processing 1k models in console command, you run Yii::$app->log->flush(true) after each model - it should greatly reduce logger overhead and still be pretty close to "real-time" (as long as processing one model does not take much time).

rob006
  • 21,383
  • 5
  • 53
  • 74