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

restart93's avatar

Laravel log with sapi suffix

I have old app that has this code

$app->configureMonologUsing(function(Monolog\Logger $monolog) {
    $filename = storage_path('logs/laravel-'.php_sapi_name().'.log');
    $handler = new Monolog\Handler\RotatingFileHandler($filename);
    $monolog->pushHandler($handler);
});

So if I use Log::info("hello"); and run it from cli it will write into file 2024-01-12-laravel-cli.log, if from web to 2024-01-12-laravel-web.log or soemthing like that.

How to do this in new laravel 10?

0 likes
1 reply
tisuchi's avatar
tisuchi
Best Answer
Level 70

@restart93 Doesn't this alternative way work for you?

Add a custom channel in config/logging.php:

'channels' => [
    'custom' => [
        'driver' => 'daily',
        'path' => storage_path('logs/laravel-'.php_sapi_name().'.log'),
        'level' => 'debug',
    ],
],

And use LOG_CHANNEL=custom in your .env

3 likes

Please or to participate in this conversation.