在 Laravel 4 中更改日志级别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16984519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing Log Levels in Laravel 4
提问by Abishek
The laravel documentation indicates on the documentationthat "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?
laravel 文档在文档中指出"The logger provides the seven logging levels defined in RFC 5424: debug, info, notice, warning, error, critical, and alert."
,但是没有提供应该在哪里更改。有人可以帮助我了解这是如何工作的以及需要更改日志级别的位置吗?
回答by Ryan
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:
我们可以将阿比舍克的回答更进一步。如果我们将日志级别添加到我们的配置文件中,我们可以根据我们所处的环境更改日志级别。在 config/app.php 中:
'log_level' => 'debug',
and in config/prod/app.php:
并在 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.
我们有可配置的日志记录。
回答by Abishek
Figured it out by looking at the LogWriterClass. 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.
通过查看LogWriter类弄清楚了。不确定这是否是正确的方法,但是 Laravel 应用程序上应该有一个配置来设置 Laravel 日志记录级别。
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
转到app/start/global.php
(https://github.com/laravel/laravel/blob/master/app/start/global.php#L36)然后Line 36
,您会找到代码
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.
希望这可以帮助那些一直在寻找这个的人。我希望有一种更简单的方法来做到这一点,而不是更改函数参数。