Laravel 5 - 更改默认日志位置,将日志文件移动到应用程序之外
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33825978/
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
Laravel 5 - change default log location, move log file outside the app
提问by Limon Monte
How can I change default log file location <project-name>/storage/logs/laravel.log
to something like /var/logs/<project-name>/laravel.log
?
如何将默认日志文件位置更改<project-name>/storage/logs/laravel.log
为类似的位置/var/logs/<project-name>/laravel.log
?
采纳答案by Limon Monte
I resolved this case by using errorlog
logging model and configuring webserver.
我通过使用errorlog
日志模型和配置网络服务器解决了这个案例。
1. Configure Laravel:
1.配置Laravel:
In config/app.php
configuration file:
在config/app.php
配置文件中:
'log' => 'errorlog'
Read more about Laravel log configuration: http://laravel.com/docs/5.1/errors#configuration
阅读有关 Laravel 日志配置的更多信息:http://laravel.com/docs/5.1/errors#configuration
2. Configure webserver (in my case Nginx):
2. 配置网络服务器(在我的例子中是 Nginx):
error_log /var/log/nginx/<project_name>-error.log;
回答by krain143
For those who don't want to use errorlog
and just really want to replace the file to log to, you can do this:
对于那些不想使用errorlog
并且只想替换要登录的文件的人,您可以这样做:
\Log::useFiles(env('APP_LOG_FILE'), config('app.log_level', 'debug'));
$handlers = \Log::getMonolog()->getHandlers();
$handler = array_shift($handlers);
$handler->setBubble(false);
on App\Providers\AppServiceProvider.php
or any Provider
for that matter. This will log to the value of APP_LOG_FILE
instead of the default laravel.log
. Set bubbling to true and the application will log on both files.
上App\Providers\AppServiceProvider.php
或任何Provider
与此有关。这将记录到值APP_LOG_FILE
而不是默认值laravel.log
。将冒泡设置为 true,应用程序将登录这两个文件。