Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Laravel 5 log file?

Tags:

My Laravel 5 website is working in a shared host with 1 GB disk space. But now I have about 100 MB log file. How I can disable log file in Laravel 5 ?

like image 235
Ashish Detroja Avatar asked Jan 07 '16 10:01

Ashish Detroja


People also ask

Can I delete Laravel log?

If you're having a space problem you can try using daily logs, it will automatically keep last X days of log (default 5). You can see it in Errors & Logging - Log Storage. Otherwise you can simply remove the storage/logs/laravel. log file or make a command to do so (like php artisane log:clear ).

Where are Laravel logs stored?

By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel. log .

How do I view Laravel logs?

You can see the generated log entries in storage/logs/laravel. log file.

What is log :: info in Laravel?

The Laravel logging facilities provide a simple layer on top of the powerful Monolog library. By default, Laravel is configured to create daily log files for your application which are stored in the storage/logs directory. You may write information to the log like so: Log::info('This is some useful information.


2 Answers

In order to completely disable logging you'll need to overwrite the default log handlers that are set by Laravel. You can easily do this with

$nullLogger = new NullHandler(); \Log::getMonolog()->setHandlers(array($nullLogger)); 

You need to call as early as possible, before request is processed, e.g. you could do that in your bootstrap/app.php:

$app->configureMonologUsing(function($monolog) {   $nullLogger = new \Monolog\Handler\NullHandler();   $monolog->setHandlers(array($nullLogger)); });  return $app; 
like image 81
jedrzej.kurylo Avatar answered Oct 24 '22 00:10

jedrzej.kurylo


If your log is very large then either you are logging a lot or your application is throwing a lot of errors. You should first examine the log and see if you can reduce data being written.

You can also switch to daily logging and then have a job to delete old log files.

The next thing to do would be to update your logging configuration to daily instead of the default single in config/app.php

Laravel will handle rotating the file daily and deleting old log files after 5 days, or the value of the app.max_log_files if you need more kept.

like image 42
devrider Avatar answered Oct 24 '22 01:10

devrider