Skip to content

[Logger] Allow to handle stdout logging in a better way #31556

Open
@eliecharra

Description

@eliecharra

Description
Since PHP 7.3, following bugs are now fixed in FPM, wich allow us to log worker output to stdout in a better "12 factor" way.

So, we could use Monolog StreamHandler when working with docker containers :

# config/packages/monolog.yaml
monolog:
    handlers:
        stdout:
            type: stream
            level: info
            path: 'php://stdout'

It works well (with a bit of fpm config) BUT ... in some case it cause several issues.

In some case a Symfony console command logs its output using the logger service instead of OutputInterface.
In that case the ConsoleHandler could be configured like below, and will allow to pass verbosity flags to commands (-v|vv|vvv) to have a fine grained control over command output.

# config/packages/monolog.yaml
monolog:
    handlers:
        stdout:
            type: stream
            level: info
            path: 'php://stdout'
        console:
            type: console
            level: info
            process_psr_3_messages: false

Above configuration should not be used as it could generated duplicate records to stdout.
ConsoleHandler is optional here, as the stdout handler will output to stdout too.
But in that case, verbosity arguments passed to CLI are not taken into account.

When using ConsoleHandler beside a stream handler on stdout, when a console command is launched logs are output on stdout twice.

I tried to use only the console handler, but it logs nothing coming from http request through fpm.

Problem :

We cannot log to stdout and use ConsoleHandler in a proper way side by side.

Possible improvements :

  • Like finger crossed handler, maybe we could allow to setup an activation strategy on stream handler to activate a given stream handler only in a web context (using SAPI const) ? But it look like a workaround rather than a real solution.
  • Improve symfony documentation to offer a clean way to logs our app to stdout as more and more people are using containers.

Could we think about it to find a better way to handle this ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions