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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:43:35  来源:igfitidea点击:

Laravel 5 - change default log location, move log file outside the app

laravellaravel-5error-loggingerror-log

提问by Limon Monte

How can I change default log file location <project-name>/storage/logs/laravel.logto 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 errorloglogging model and configuring webserver.

我通过使用errorlog日志模型和配置网络服务器解决了这个案例。

1. Configure Laravel:

1.配置Laravel:

In config/app.phpconfiguration 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 errorlogand 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.phpor any Providerfor that matter. This will log to the value of APP_LOG_FILEinstead 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,应用程序将登录这两个文件。