1

I would like to know if there is any way to limit the size of a log file in Laravel. I am doing the rotate to create a Log per day, and that these are deleted after a certain time like this:

'custom' => [
            'driver' => 'stack',
            'channels' => ['daily'],
            'tap' =>  ['CustomLogger::class'],
            'days' => 15
           ] 

What creates a log file per day with the format laravel-2022-10-10.log, what I need now is to put a size limit on that Log. That is to say that this file cannot exceed 300mb and if it does, another new file is created that now would be called something like laravel-2022-10-10(2).log

Is there something that makes this possible in Laravel?

  • Not that I know of, but you can review [the documentation](https://laravel.com/docs/9.x/logging) and see if there's something available. Beyond that, you might need some kind of custom implementation, or maybe consider less logging? None of my daily development logs for Laravel projects have ever even come _close_ to 300MB. – Tim Lewis Oct 11 '22 at 20:29
  • Also, related questions: https://stackoverflow.com/questions/68725221/limit-laravel-log-file-size (logrotate), https://stackoverflow.com/questions/55369654/how-to-set-max-size-for-log-file-using-monolog (not Laravel-specific), https://laracasts.com/discuss/channels/laravel/how-can-i-set-a-log-file-size (external solution, etc.) – Tim Lewis Oct 11 '22 at 20:31
  • 4
    This is not supported out of the box but you can always shedule a background operation that checks the current size of today's log and moves (renames) it if it's above a certain size (this would mean the latest log will be laravel-YYYY-MM-DD.log though) – apokryfos Oct 11 '22 at 20:51

0 Answers0