Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

princeoo7's avatar

How to create Custom log folder for the date and custom log file based on task in laravel

I have 3 -5 task daily planned. what i want is to get log details based on task in separate file so that when i need to read the log, its not to big and easy to find. also, I want this log files to be created in a folder under log folder with date as name.

example:

-log (folder)
    -2019-11-27 (folder)
        -errors.log
        -task1.log
        -task2.log
        -task3.log

    -2019-11-28 (folder)
        -errors.log
        -task1.log
        -task2.log
        -task3.log

    -2019-11-29 (folder)
        -errors.log
        -task1.log
        -task2.log
        -task3.log

and so on...

0 likes
4 replies
Sinnbeck's avatar

I don't think monolog supports folders. I have never found any reference to that sadly

Untested but you should be able to make a custom channel for each that logs to a file with the name task1-2019-11-20.log etc.

'task1' => [
            'driver' => 'daily',
            'path' => storage_path('logs/task1.log'),
            'level' => 'debug',
            'days' => 14,
        ],

And then log to each like this

Log::channel('task1')->info('Something happened!');
1 like
Sinnbeck's avatar

Another idea could by to try this. I am not sure if it will work though as the directory does not exist

'task1' => [
            'driver' => 'single',
            'path' => storage_path('logs/' . Carbon::now()->toDateString() . '/task1.log'),
            'level' => 'debug',
        ],
princeoo7's avatar

do you have any idea about below ?

    'stderr' => [
        'driver' => 'monolog',
        'handler' => StreamHandler::class,
        'formatter' => env('LOG_STDERR_FORMATTER'),
        'with' => [
            'stream' => 'php://stderr',
        ],
    ],
Sinnbeck's avatar

I am quite certain that that is the error channel for artisan commands. It writes to the console.

Please or to participate in this conversation.