8p / EightPointsGuzzleBundle

⛽️ Integrates Guzzle 6.x, a PHP HTTP Client, into Symfony
MIT License
440 stars 71 forks source link

[Doc] Configure Guzzle Logger Middleware to log into a different Monolog channel #244

Open florianpreusner opened 5 years ago

florianpreusner commented 5 years ago

Created monolog.yml under /config (SF 4.1):

    use_microseconds: false

    channels:
        - eight_points_guzzle

    handlers:
        eight_points_guzzle:
            channels: [eight_points_guzzle]
            type: stream
            path: "%kernel.logs_dir%/eight_points_guzzle.log"
            level: info

---- created from comment by renatogcarvalho (Symfony Dev Slack, #8p-guzzlebundle, 18/11/24, 9:49 AM) ----

Hello @channel!

First of all, thank you for this amazing bundle. It was great to find a tool to accomplish exactly what I was already working on. Much appreciated. I got a question though. Is there a way to configure the Guzzle Logger Middleware to log into a different Monolog channel? Usually I like to organize my application logs into different channels sometimes specific to some services just so I can tail logs for that service alone without doing any grep, etc. Also, for some reason it looks like the formatter override is not working for me. Maybe I'm doing something wrong?

    eight_points_guzzle.symfony_log_formatter.pattern: '[{datetime}] guzzle.{log_level}: HTTP/{code} {method} {uri} {res_body}'

output:

It seems that is appending instead of replacing. Oh I see, it looks like you only allow to override the message itself, not the whole line.

renatogcarvalho [9:49 AM] Ok, regarding the issue related with the Monolog channel I figured out how to configure it to log into a different file. Just for future reference for anybody that might be interested in accomplish this as well.

Created monolog.yml under /config (SF 4.1):

    use_microseconds: false

    channels:
        - eight_points_guzzle

    handlers:
        eight_points_guzzle:
            channels: [eight_points_guzzle]
            type: stream
            path: "%kernel.logs_dir%/eight_points_guzzle.log"
            level: info

You guys might be interested in documenting this. Have a good one everybody.