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

M4verick's avatar

Laravel STDOUT Logs for AWS CloudWatch in a Dockerized App

Hello everyone , I’m working on a Dockerized application and need to make sure that all of our logs go to STDOUT so they can be collected and sent to AWS CloudWatch (our infrastructure already handles logs from STDOUT). I’ve been told not to use the AWS SDK to create custom log groups or set up log drains, since Docker automatically captures STDOUT logs. But I’m not sure if there’s anything specific I need to do to make sure both standard logs and error logs get sent properly to CloudWatch.

Here is my configuration so far :

config/logging.php

    'channels' => [

        'stack' => [
            'driver' => 'stack',
            'channels' => ['single', 'stdout', 'stderr'],
            'ignore_exceptions' => false,
        ],

        'stdout' => [
            'driver' => 'monolog',
            'level' => env('LOG_LEVEL', 'debug'),
            'handler' => StreamHandler::class,
            'with' => [
                'stream' => 'php://stdout',
            ],
        ],

		'stderr' => [
            'driver' => 'monolog',
            'level' => env('LOG_LEVEL', 'debug'),
            'handler' => StreamHandler::class,
            'formatter' => env('LOG_STDERR_FORMATTER'),
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

Also, when i try to run "docker logs <container_id>" , i see that my logs are appeared , but in my aws cloudwatch are not. Anyone can give me any suggestions about this ? Thanks

0 likes
3 replies
martinbean's avatar

@m4verick You don’t need to mess about with the default stack channel configuration.

Just create a new channel for stdout (copying the stderr one):

  'stderr' => [
      'driver' => 'monolog',
      'level' => env('LOG_LEVEL', 'debug'),
      'handler' => StreamHandler::class,
      'formatter' => env('LOG_STDERR_FORMATTER'),
      'with' => [
          'stream' => 'php://stderr',
      ],
  ],

+ 'stdout' => [
+     'driver' => 'monolog',
+     'level' => env('LOG_LEVEL', 'debug'),
+     'handler' => StreamHandler::class,
+     'formatter' => env('LOG_STDERR_FORMATTER'),
+     'with' => [
+         'stream' => 'php://stdout',
+     ],
+ ],

And then set your LOG_CHANNEL environment variable to stdout to use this new channel.

M4verick's avatar

@martinbean The reason why i have include them in my stack channel is because i need to store them also in my laravel storage (laravel.log file). And my LOG_CHANNEL env variable is set to "LOG_CHANNEL=stack". What do you think about that ?

martinbean's avatar

@M4verick By default, the channels that make up the stack channel are again controlled by an environment variable. So you can set an environment variable for LOG_STACK and set its value to single,stdout,stderr. But it’s quite strange to send errors to both STDOUT and STDERR.

Please or to participate in this conversation.