Laravel logging to console using standard output stdout

This quick post shows how to setup Laravel logging to console as the logging configuration has been changed in version 5.6. Now, we are able to easily modify config/logging.php configuration file to our needs just by creating new channel – standard output.

It will be created in same way as the existing standard error stderr channel in configuration. That means we just add new channel type stdout to channels array using same stream handler but with another stream php://stdout. If we also want to log into laravel.log then using stack channel we can log into multiple channels. See example below.

config/logging.php

<?php

return [
    'default' => env('LOG_CHANNEL', 'stack'),
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'stdout'],
        ],
        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],
        'stdout' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'with' => [
                'stream' => 'php://stdout',
            ],
        ],
    ],
];

Leave a Reply

Your email address will not be published. Required fields are marked *