classification
Title: _handle_existing_loggers should respect loggers that were manually disabled
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ronserruya2, vinay.sajip
Priority: normal Keywords:

Created on 2021-06-22 12:57 by ronserruya2, last changed 2021-09-02 19:02 by vinay.sajip. This issue is now closed.

Messages (3)
msg396327 - (view) Author: Ron Serruya (ronserruya2) Date: 2021-06-22 12:57
The method `_handle_existing_loggers` in the logging lib (called when configuring loggers using dictConfig) iterates over all existing loggers and sets their .disabled attribute according to the `disable_existing_loggers` parameter (usually set to false)

However this only lets the user completely disable/enable all existing loggers, and there is no way to tell the function to keep the value to what it was

This example was how I found about it

1. Imported the pkg ddtrace, which writes some logs that I'm not interested in

2. Disabled the ddtrace logger 
`logging.getLogger('ddtrace.internal.writer').disabled = True`

3. Imported the pkg Sanic, which configures its logging using `logging.configure.dictConfig()`, with `disable_existing_loggers` set to False, as it doesn't want to disable all of the loggers that were created before it

4. `_handle_existing_loggers` re-enabled the logger that I manually disabled before



Ps. apologies if this is not the correct place, I don't really see this as a bug, more like a feature request, however the only place I found for feature requests were PEPs, which this obviously isnt
msg398685 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-08-01 06:31
Why couldn't you just do the logging configuration first, then disable any loggers you need to after that?

You can pass a custom configuration dict when instantiating a Sanic app. That could contain a setting for the ddtrace logger, e.g. to set its level to logging.CRITICAL + 1.
msg400945 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2021-09-02 19:02
Closing, as no further feedback received on this issue. You can reopen if you have an answer to my question.
History
Date User Action Args
2021-09-02 19:02:10vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg400945

stage: resolved
2021-08-01 06:31:05vinay.sajipsetmessages: + msg398685
2021-06-23 07:49:39vinay.sajipsettype: enhancement
versions: + Python 3.11, - Python 3.8
2021-06-22 13:05:49xtreaksetnosy: + vinay.sajip
2021-06-22 12:57:06ronserruya2create