简体   繁体   中英

Separate Log Files Laravel 8

I am trying to have Error messages and debug messages write to separate log files, laravel.log for error messages and debug.log for debug messages. As of now, debug messages are not writing to the error log, which is good but error messages are still writing to the debug log.

here is the config from logging.php:

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'syslog'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'error',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel-'.php_sapi_name().'-'.$processName.'.log'),
            'level' => 'debug',
            'days' => 7,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'syslog' => [
            'driver' => 'single',
            'level' => 'debug',
            'path' => storage_path('logs/debug.log'),
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'error',
        ],
    ],

];

And when I am writing a debug message, I write to the specific channel:

Log::channel('syslog')->debug($message);

I want to stop error messages from writing to debug.log, and only write to laravel.log

Thanks!

Okay I figured this out for anyone who may need it in the future!

So Laravel's stack channel contains any other channel that you want to be active; and the default channel when writing something like Log::debug('message');will look like this:

 'default' => env('LOG_CHANNEL', 'stack')

With my configuration from above, changing the default to 'single', which I have set as the error level will look like this:

 'default' => env('LOG_CHANNEL', 'single')

Just be sure to log to specific channels when logging( I built a helper function for this ) and you will be good!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM