Laravel logging best practice
Updated: 28th April 2025
Tags: laravel
First of all there are different ways to organize logs.
Personally I like to have daily logs based on interface.
The most important is 'path' => storage_path('logs/laravel-'.php_sapi_name().'.log'),
that will use different file for different interface.
Must have if you use any artisan or tinker commands.
So here sample config I use:
Laravel 6+
<?php
//config/logging.php
return [
//...
'custom' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel-'.php_sapi_name().'.log'),
'level' => env('LOG_LEVEL', 'debug'),
// 'days' => env('LOG_DAILY_DAYS', 14),
'replace_placeholders' => true,
],
];
Laravel 5
If you use old laravel that doesn’t have file config/logging.php
, then modify bootstrap/app.php
<?php
//bootstrap/app.php
//.....
$app->configureMonologUsing(function(Monolog\Logger $monolog) {
$filename = storage_path('logs/laravel-'.php_sapi_name().'.log');
$handler = new Monolog\Handler\RotatingFileHandler($filename);
$monolog->pushHandler($handler);
});
return $app;
Useful tools for viewing logs
Personally I find useful to have logviewer, just don’t forget to make middleware so only you can view them.
rap2hpoutre/laravel-log-viewer laravel 5+
opcodesio/log-viewer laravel 8+, php 8+