'Laravel 5 - change default log location, move log file outside the app
How can I change default log file location <project-name>/storage/logs/laravel.log
to something like /var/logs/<project-name>/laravel.log
?
Solution 1:[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;
Solution 2:[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.
Solution 3:[3]
For anyone still coming across this post in hopes of changing their log file location, I believe this is now easier in newer versions of Laravel. I am currently using 8.x
In your /config/logging.php
you can define the path
for your single and daily logs. Just update whichever one your are looking to change. Just make sure you also include the name of the log file, not just the path to where you'd like it saved.
'single' => [
'driver' => 'single',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
],
'daily' => [
'driver' => 'daily',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Limon Monte |
Solution 2 | krain143 |
Solution 3 | Terrence |