symfony / monolog-bundle

Symfony Monolog Bundle

Home Page:symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bubble: false property doesn't work with doctrine channel like expected

bobahvas opened this issue · comments

I tried to use the following config to get only DEBUG level of doctrine logs.

query:
    type: stream
    path: "%kernel.logs_dir%/query.log"
    level: debug
    bubble: false
    channels: ["doctrine"]
    formatter: 'monolog.formatter.json'

So, I expected to see in the log something like:

{"message":"Executing query: SELECT ...","context":{"sql":"SELECT ..."},"level":100,"level_name":"DEBUG","channel":"doctrine","datetime":"2023-04-23T13:04:42.861552+00:00","extra":{}}

However, I see the following (info - higher level included as well):

{"message":"Connecting with parameters...","context":{}},"level":200,"level_name":"INFO","channel":"doctrine","datetime":"2023-04-23T13:04:42.840105+00:00","extra":{}}
{"message":"Executing query: SELECT ...","context":{"sql":"SELECT ..."},"level":100,"level_name":"DEBUG","channel":"doctrine","datetime":"2023-04-23T13:04:42.861552+00:00","extra":{}}
{"message":"Disconnecting","context":{},"level":200,"level_name":"INFO","channel":"doctrine","datetime":"2023-04-23T13:04:42.876087+00:00","extra":{}}

Bubble: false property works well when I use the following config for the app category:

info_log:
    type: stream
    path: "%kernel.logs_dir%/info.log"
    level: info
    bubble: false
    channels: ["app"]
    formatter: 'monolog.formatter.json'
debug_log:
    type: stream
    path: "%kernel.logs_dir%/debug.log"
    level: debug
    bubble: false
    channels: ["app"]
    formatter: 'monolog.formatter.json'

Sorry for the open issue, logging works another way.

You have to use filters for other handlers.
For example, you collect all logs with level "debug" (can be set min and max levels as well) and from channel "doctrine". After that, you provide filtered results to your "query" handler.

filter_for_query:
    type: filter
    accepted_levels: [debug]
    channels: ["doctrine"]
    handler: query

query:
    type: stream
    path: "%kernel.logs_dir%/query.log"
    formatter: 'monolog.formatter.json'

I suggest improving the documentation and maybe adding a current example with an explanation.