10

I have a PHP/Symfony app running in Docker which uses Monolog to log to stdout/stderr. This all works great, except when running Symfony console commands inside a container.

monolog:
    handlers:
        stdout:
            type: filter
            handler: stdout_unfiltered
            max_level: notice
            channels: ['!event']

        stdout_unfiltered:
            type: stream
            level: debug
            path: 'php://stdout'

        stderr:
            type: stream
            level: warning
            channels: ['!event']
            path: 'php://stderr'

        console:
            type: console
            channels: ['!console', '!doctrine', '!event']
            process_psr_3_messages: false

The problem is that whenever a command is executed, the "stdout", "stderr" and "console" handlers log to the current terminal process. This causes the console output to be messed up, and docker logs not to contain the log entries: https://i.stack.imgur.com/NRris.png.

Would there be an easy way to always send the logging output to the php-fpm (or any worker) process?

Egon Olieux
  • 709
  • 1
  • 10
  • 18

1 Answers1

0

log to the file /proc/1/fd/1 (or fd/2)

monolog:
    handlers:
        ...
        stdout_unfiltered:
            type: stream
            level: debug
            path: '/proc/1/fd/1'
        stderr:
            type: stream
            level: warning
            channels: ['!event']
            path: '/proc/1/fd/2'
        ...

Maybe you can check where this point to and redirect there (docker exec aContainer ls -l /proc/1/fd/2), but this could change depending on the container start.

Not sure if it is ideal, but it works (when symfony has write permisison for /proc/1/fd/*).

simohe
  • 613
  • 7
  • 20
  • Just found out I am not the first with the idea of redirecting to `/proc/1/fd/1`: https://stackoverflow.com/a/46220104/4124767 – simohe Jul 13 '20 at 15:44