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

martinszeltins's avatar

How to create a custom Log file?

I am trying to understand how I could write a log message to a custom log. Right now I am able to write to storage/logs/laravel.log using Log::debug('message')

\Log::debug('Hello world!');

And the message gets added to laravel.log which is great!

But I would also like to add a custom log for example /storage/logs/myownlog.log

\Log::debug('Hello world!'); // logs to laravel.log
\Log::mycustomlog('Hello!'); // logs to myownlog.log

I was reading through the documentation on it but I could not understand what I need to change in /config/logging.php to add a custom log file. Channels, stacks and drivers seem really confusing to me....

Laravel 5.6

0 likes
8 replies
Ishatanjeeb's avatar

To write a log file to another location, use the method useDailyFiles or useFiles, and then info to log to the log file at the path you just specified something like below:

    Log::useFiles('path/to/file.log');
    Log::info([info to log]);
martinszeltins's avatar

@Ishatanjeeb I get an error

Call to undefined method Monolog\Logger::useFiles()
public function testing()
{
     Log::useFiles('logs/mycustom.log');
     Log::info('Hello world!');
}
Ishatanjeeb's avatar

try this one

public function testing()
{
 Log::useFiles(storage_path().'/logs/mycustom.log');
 Log::info('Hello world!');
}
Ishatanjeeb's avatar

try this one

public function testing()
{
 Log::useFiles(storage_path().'/logs/mycustom.log');
 Log::info('Hello world!');
}
1 like
martinszeltins's avatar

After some digging around I found that I could add a channel to config/logging.php like this

'customlog' => [
            'driver' => 'single',
            'path' => storage_path('logs/custom.log'),
            'level' => 'info',
],

and write to it like this

Log::channel('customlog')->info('Hello world!!');
17 likes

Please or to participate in this conversation.