[issue46957] Logger with a custom class breaks on copy
Govinda Totla
report at bugs.python.org
Tue Mar 8 07:45:10 EST 2022
New submission from Govinda Totla <govinda.totla.cse16 at itbhu.ac.in>:
The logging module allows you set a custom Logger class as the default logger. However, this breaks when we try to copy the logger which was created before setting the logger class
```
import copy
import logging
# Some module we don't control
oldLogger = logging.getLogger("abc")
# Some module where we want to change over to custom logging
class MyLogger(logging.Logger):
pass
# Override the manager, root, etc., so everything uses our class
logging.setLoggerClass(MyLogger)
logging.root = root = MyLogger("", logging.WARNING)
logging.Logger.manager = logging.Manager(root)
newLogger = logging.getLogger("def")
# Later on this happens, which internally calls __reduce__
copy.deepcopy(oldLogger)
```
----------
components: Library (Lib)
messages: 414750
nosy: govinda18
priority: normal
severity: normal
status: open
title: Logger with a custom class breaks on copy
type: crash
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46957>
_______________________________________
More information about the Python-bugs-list
mailing list