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

只愿长相守 提交于 2019-12-04 19:35:03

问题


How can I change default log file location <project-name>/storage/logs/laravel.log to something like /var/logs/<project-name>/laravel.log?


回答1:


I resolved this case by using errorlog logging model and configuring webserver.

1. Configure Laravel:

In config/app.php configuration file:

'log' => 'errorlog'

Read more about Laravel log configuration: http://laravel.com/docs/5.1/errors#configuration

2. Configure webserver (in my case Nginx):

error_log    /var/log/nginx/<project_name>-error.log;



回答2:


For those who don't want to use errorlog and just really want to replace the file to log to, you can do this:

\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.



来源:https://stackoverflow.com/questions/33825978/laravel-5-change-default-log-location-move-log-file-outside-the-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!