Changing Log Levels in Laravel 4
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.
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.