shutdown function of logging module does not empty _loggers
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start in logging.py around line 213 and reproduce the failure with the code in the issue. Check how logging.shutdown() handles _loggers and closed handlers, then verify that reusing the logger after shutdown can add a new FileHandler and emit a message without ValueError.
Written by the indexing model from the issue text.
Description
if I want to reuse logger after call shutdown(), I can recreate log_a , add file_handler , but it will failure on log.xxx
Traceback (most recent call last): ... File "logging.py", line 141, in info File "logging.py", line 135, in log File "logging.py", line 71, in emit ValueError:
the root cause is, after execute logging.shutdown() , all logger remain in _loggers variables, so all handlers remain in logger.handlers, but the old file_handlers was closed, so emit method failure.
we can run follow code to verify it.
import logging
log_a = logging.getLogger('a')
log_a.setLevel(logging.DEBUG)
file_handler = logging.FileHandler('log.txt')
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
log_a.addHandler(file_handler)
log_a.debug('write to file')
print(logging._loggers)
print(log_a.handlers)
logging.shutdown()
log_a = logging.getLogger('a')
log_a.setLevel(logging.DEBUG)
file_handler = logging.FileHandler('log.txt')
file_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
file_handler.setFormatter(formatter)
log_a.addHandler(file_handler)
log_a.debug('write to file')
print(logging._loggers)
print(log_a.handlers)
to fixed it, pass name to pop method in line 213
logging._loggers.pop(logger.name, None)
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 1.1k
- Avg merge
- 7d 6h
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from micropython/micropython-lib
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
micropython/micropython-lib#1074 ·
-
needs-info
Difficulty 1/5 Under an hour Newbie friendliness 72/100
micropython/micropython-lib#943 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
micropython/micropython-lib#931 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
micropython/micropython-lib#795 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
micropython/micropython-lib#762 ·
All issues in micropython/micropython-lib
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·