Laravel's daily driver for generating logs is great, but sometimes you wish you could break it up even more. These code snippets will help you break up your laravel logs by year and month folders
For example, the channel error
from these snippets will gennerate files such as
/storage/logs/errors/2021/02/laravel-2021-02-28.log
/storage/logs/errors/2021/03/laravel-2021-03-01.log
/storage/logs/errors/2021/03/laravel-2021-03-02.log
Our custom RotatingFileHandler.php
extends Monolog's Monolog\Handler\RotatingFileHandler
, and we simply prepend the year and month before the file name before passing it to the parent constructor which will deal with the rest.
Hope this can help others who wishes for similar sturctures, and hope you all try out customizing it in any way you like. You can also split the folders by log levels and get files like
/storage/logs/error/laravel-2021-03-02.log
/storage/logs/warning/laravel-2021-03-02.log
/storage/logs/debug/laravel-2021-03-02.log
or basically any way you want by modifying the constructor.
Happy coding :)