Laravel Lumen change log file name

Lumen logs are written to /storage/logs and the default name is lumen.log . How to change file name to say xyz.log ?

+5
source share
2 answers

As indicated in the comments, the location and log file name are hard-coded.

Now, if for some good reason you want to change it, you can always extend the Laravel\Lumen\Application class and override the getMonologHandler() method.

Create a new Application.php file in the app folder that looks like

 namespace App; use Laravel\Lumen\Application as LumenApplication; use Monolog\Formatter\LineFormatter; use Monolog\Handler\StreamHandler; use Monolog\Logger; class Application extends LumenApplication { protected function getMonologHandler() { return (new StreamHandler(storage_path(env('APP_LOG_PATH', 'logs/xyz.log')), Logger::DEBUG)) ->setFormatter(new LineFormatter(null, null, true, true)); } } 

Now change

 $app = new Laravel\Lumen\Application( 

to

 $app = new App\Application( 

in bootstrap\app.php file

Now the file of your Voila file is called xyz.log . Moreover, you can change it to whatever you want by specifying the environment variable APP_LOG_PATH ie via .env file

 APP_LOG_PATH=logs/abc.log 
+10
source

There is a publicly accessible configureMonologUsing available here and links to here which can be used to override the default behavior without extending the application.

Here you can use it in your bootstrap / app.php:

 $app->configureMonologUsing(function(Monolog\Logger $monolog) { $handler = (new \Monolog\Handler\StreamHandler(storage_path('/logs/xyz.log'))) ->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true)); return $monolog->pushHandler($handler); }); 

Bonus: also choose RotatingFileHandler monologues.

+5
source

All Articles