Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Log Levels in Laravel 4

The laravel documentation indicates on the documentation that "The logger provides the seven logging levels defined in RFC 5424: debug, info, notice, warning, error, critical, and alert.", but where should this be changed is something that is not provided. Could someone help me understand how this works and where the log level needs to be changed?

like image 947
Abishek Avatar asked Jun 07 '13 12:06

Abishek


People also ask

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.

Where are laravel logs stored?

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 .

How do I enable error logs in laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.

How do I disable laravel logging?

go to vendor->laravel->framework->src->Illuminate->Log->Writer. php and then comment out all the code within function __call like below. You log will never be save.


2 Answers

We can take Abishek's answer one step further. If we add the log levels to our config files, we can change the log level based on the environment we're in. In config/app.php:

'log_level' => 'debug',

and in config/prod/app.php:

'log_level' => 'warning',

We then change the daily logger to

Log::useDailyFiles(storage_path() . '/logs/' . $logFile, 0, Config::get('app.log_level'));

and we have configurable logging.

like image 159
Ryan Avatar answered Oct 06 '22 19:10

Ryan


Figured it out by looking at the LogWriter Class. Not sure if this is the right approach but, there should be a config on the Laravel App that should set the Laravel Logging Level.

This is what currently needs to be done to change the logging level.

Go to app/start/global.php (https://github.com/laravel/laravel/blob/master/app/start/global.php#L36) and on Line 36, you would find the code

Log::useDailyFiles(storage_path().'/logs/'.$logFile);

This needs to be changed to

Log::useDailyFiles(storage_path() . '/logs/' . $logFile, 0, 'error');

The third parameter is where the log level needs to be changed and the following are the log levels that can be used

  • debug
  • info
  • notice
  • warning
  • error
  • critical
  • alert

Hope this helps who ever have been searching for this. I hope there is a simpler way to do this instead of changing the function parameter.

like image 34
Abishek Avatar answered Oct 06 '22 21:10

Abishek