In Laravel I'm defining a custom log file in /config/logger.php
:
'mycustomlog' => [
'driver' => 'stack',
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
],
Here's my stack driver for context:
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'syslog'],
'ignore_exceptions' => false,
],
and I'm calling it as follows:
Log::channel('mycustomlog')->info($e);
What I expect to happen:
A (daily) log file is created and the exception is logged. I.e mycustomlog-2019-11-07.log
What actually happens:
No log file is created, but the following error is logged to laravel.log
:
[2019-11-07 10:25:31] laravel.EMERGENCY: Unable to create configured logger. Using emergency logger. {"exception":"[object] (ErrorException(code: 0): Undefined index: channels at /var/www/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:232)
SOLUTION:
'mycustomlog' => [
'driver' => 'daily',
'channels' => ['syslog'],
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
],
By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel. log .
Laravel logging is based on "channels". Each channel represents a specific way of writing log information. For example, the single channel writes log files to a single log file, while the slack channel sends log messages to Slack. Log messages may be written to multiple channels based on their severity.
You will need to have channels in the config logger.php
see here. The point of the stack driver is to report to multiple channels.
'mycustomlog' => [
'driver' => 'stack',
'channels' => ['daily'],
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
],
If you don't want it to be in the stack you can have your config to point to the single driver like this
'mycustomlog' => [
'driver' => 'single',
'path' => storage_path('logs/mycustomlog.log'),
'level' => 'info',
]
Then call it the same way you tried on your own.
Log::channel('mycustomlog')->info($e);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With