I have a Symfony app hosted with Docker on AWS. For logging I use AWS CloudWatch.
For example: the database connection can not be established. If I use the default monolog configuration, I get the error in the file /project/var/log/prod.log. When I change the path to php://stderr, I expect the same message in CloudWatch, but it doesn't appear.
I have modified the index.php for test reasons:
<?php
echo ini_get('error_log');
error_log('error_log');
file_put_contents('php://stderr', 'file_put_contents', FILE_APPEND);
The output is: /proc/self/fd/2
(docker logs target)
In CloudWatch I get the message error_log
, but not file_put_contents
.
I have no idea where the problem is. Maybe the Symfony app is misconfigured. But since the message file_put_contents
is missing - which runs without Symfony - I'm not sure.
This is the monolog configuration:
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_404s:
# regex: exclude all 404 errors from the logs
- ^/
nested:
type: stream
# path: "%kernel.logs_dir%/%kernel.environment%.log"
path: "php://stderr"
level: debug
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
deprecation:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
deprecation_filter:
type: filter
handler: deprecation
max_level: info
channels: ["php"]
This is the default configuration, except the line path: "php://stderr"
.