Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel logging: extra square brackets at end of log lines?

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!

like image 404
curtisdf Avatar asked Nov 12 '13 17:11

curtisdf


People also ask

What is error log in Laravel?

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.

What is log :: info in Laravel?

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. ');

Where is storage logs Laravel log?

By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel.

What are the Laravel log levels?

The logger provides the eight logging levels defined in RFC 5424: emergency, alert, critical, error, warning, notice, info and debug.


1 Answers

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))
);
like image 108
TachyonVortex Avatar answered Sep 21 '22 16:09

TachyonVortex