rigobcastro's avatar

My laravel.log size is 31 GB

Hello everyone, I have this problem in a very short time my laravel.log file grows up to 30 GB or more. I do not know why. My environment is production and I have the debug in false. Everything is normal, I have NewRelic installed.

Thank you for any help.

0 likes
17 replies
michaeldyrynda's avatar

What's in the logfile? You're probably getting a lot of exceptions. Laravel will log the stacktrace to this file in production, rather than sending it to the browser. That's the only reason I can think that it would be filling up. There's a good chance it's alerting you to something you need to fix, especially when there's 31gb of text in it.

Check that, then look at setting up log rotation, that way you can move out laravel.log to laravel-yyyy-mm-dd.log or similar.

Inside config/app.php there is a log key, which you can set to single, daily, syslog, or errorlog. Set it to daily in order to get rotation running. Keep in mind this means you will get your logs spread across multiple days if you're not cleaning out old records.

You can use syslog to log directly to your system's logfile, which will automatically be setup to rotate out but - depending on rotation of that file - you'll lose historical tracking after a few days.

3 likes
jlrdw's avatar

@deringer if a site is not in use for a few moments can the contents of that file be deleted, what is the best way to purge that file? And shouldn't that file be set up not to grow that big?

michaeldyrynda's avatar

You can delete the log file any time, it will be created if it's not there.

Laravel gives you the option to at least group the logs by day, which will also take care of deleting old log files. By default, the daily log option will keep 5 days. You can change this value by adding a log_max_files key in your config/app.php.

toniperic's avatar

@jlrdw if you don't use some services for better error tracking, such as BugSnag, you should definitely have a cronjob that checks the file on a daily basis and either deletes it, archives it or whatever.

Laravel's exception handler has nothing to do with the file-size, but if you prefer you could write your own exception handler that checks the file-size before logging the exception, and use that one instead.

@deringer logrotate is actually run us a cronjob as well, right?

michaeldyrynda's avatar

I would definitely be checking to see why the logfile is 31gb. If you fix whatever bug exists, the logfile shouldn't grow too much.

@toniperic yeah, logrotate is run as a daily cron specifically to handle rotation of logfiles. It can be configured more frequently than that if it's watching filesize for example.

1 like
jlrdw's avatar

Do I have to set up such a cron job or is that automatic when you set it in the config?

rigobcastro's avatar

@deringer Thanks but the open of this file is impossible because its size is very big. The application is normal, don't have jobs or some custom exception. In fact, NewRelic alerts me about this size and no more, don't alert me about other errors. I always delete this file.

toniperic's avatar

@rigobcastro the file wasn't 31GB of text all for nothing. You better keep an eye on it in the future, there are probably some exceptions being thrown.

jlrdw's avatar

Where is that file located on the production server? And can it be deleted while the server is in use? I figured the server would have to be temporarily down?

rigobcastro's avatar

@jlrdw This located on storage/logs folder, and I can't open this, I need download for know more about this, but I don't know how in Forge.

toniperic's avatar

You don't have to download the file.

Ssh into the server and use vim.

vim path/to/laravel/storage/logs/whatever.log

Quick note when opening huge file: press CTRL-C.

Vim tries to read in the whole file initially, to do things like syntax highlighting and number of lines in file, etc. Ctrl-C will cancel this enumeration (and the syntax highlighting), and it will only load what's needed to display on your screen.

jlrdw's avatar

Can you override the file via FTP? And on a fresh set up is there anything in that file or is it blank? This is a very intriguing problem that I was unaware of. Where is @bashy when we need him?

jlrdw's avatar

@toniperic Does vim work on shared hosting as well. I don't even know what vim is.

alexm-cripps's avatar

Just noticed our log file is pretty big which is what brings me here. To those wondering how to read enormous log files don't use a text editor, use a pager like less.

londoh's avatar

Just ssh in, switch to log dir, run

tail -fn 100 laravel.log

and watch it scroll by

And yea you need to make sure its rotated by one of the methods others suggest

1 like

Please or to participate in this conversation.