I'm newish to Laravel, and I've noticed when I use its Monolog-based logging, e.g. Log::info('blah blah')
, the lines it writes to my logfile are suffixed with two empty sets of square brackets. What are they for, and how can I turn them off? They're not helpful in the slightest. I've tried digging into the source code and Googling a bit, but I'm not seeing any explanation.
Example:
[2013-11-12 09:13:16] log.INFO: Hello world [] []
[2013-11-12 09:13:31] log.INFO: My silly log message [] []
Thanks!
Logging is an important mechanism by which system can log errors that are generated. It is useful to improve the reliability of the system. Laravel supports different logging modes like single, daily, syslog, and errorlog modes. You can set these modes in config/app. php file.
The Laravel logging facilities provide a simple layer on top of the powerful Monolog library. By default, Laravel is configured to create daily log files for your application which are stored in the storage/logs directory. You may write information to the log like so: Log::info('This is some useful information. ');
By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel.
The logger provides the eight logging levels defined in RFC 5424: emergency, alert, critical, error, warning, notice, info and debug.
Here's a solution which combines curtisdf's answer with this answer by Seldaek, and doesn't require subclassing Monolog's LineFormatter
.
Assuming your app/start/global.php
file contains:
Log::useFiles(storage_path() . '/logs/laravel.log');
Replace that with:
use Monolog\Handler\StreamHandler;
use Monolog\Logger as MonologLogger;
use Monolog\Formatter\LineFormatter;
// Use custom LineFormatter, with ignoreEmptyContextAndExtra enabled
Log::getMonolog()->pushHandler(
(new StreamHandler(
storage_path() . '/logs/laravel.log',
MonologLogger::DEBUG
))->setFormatter(new LineFormatter(null, null, true, true))
);
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