Writing own log messages to own log file

Hi guys,

I would like to log my own log messages in a seperate file. I’ve read that I can make something with categories, but I couldn’t get it. My log config:


'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'flushInterval' => 1,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'levels' => ['info', 'error', 'warning'],

                    'exportInterval' => 1,

                    'logFile' => '@app/runtime/logs/trace.log',

                ],

            ],

        ],

Then if I write


\Yii::info('This is some test..');

the the info-log entry is visible in my trace.log file. But is there any possibility for a "custom.log" file only for own log entries?

Thanks

Set ‘categories’ in your config like:




'log' => [

            'traceLevel' => YII_DEBUG ? 3 : 0,

            'flushInterval' => 1,

            'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'categories' => ['my_category'],

                    'exportInterval' => 1,

                    'logFile' => '@app/runtime/logs/my.log',

                ],

            ],

        ],



Then use logger as:




\Yii::info('blah blah', 'my_category');



Got an answer from "cebe" at the Github issues. There need to be "logVars" overwritten to filter unwanted log entries. That helped me. Thanks.


'targets' => [

                [

                    'class' => 'yii\log\FileTarget',

                    'logVars' => [],

                    'categories' => ['own'],

                    'exportInterval' => 1,

                    'logFile' => '@app/runtime/logs/my.log',

                ],

            ],