MemoryHandler can't be setup through a DictConfig if any other logger is setup after it
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Bug report
Bug description:
This is the logging that's failing.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"fine-logger1": {
'level': logging.INFO,
'formatter': 'verbose-console',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
},
"fine-logger2": {
"level": logging.INFO,
"class": "logging.FileHandler",
"filename": Path("logs/somefilename.log"),
"mode": "a",
"formatter": "verbose",
},
"fine-logger3": {
"level": logging.DEBUG,
"class": "logging.FileHandler",
"filename": Path("logs/errors/somefilename.log"),
"delay": True,
"formatter": "verbose",
},
"bugged-logger3": {
"level": logging.DEBUG,
"class": "logging.handlers.MemoryHandler",
"capacity": 9999999,
"flushLevel": logging.ERROR,
"target": "fine-logger3",
"flushOnClose": False,
},
},
"loggers": {
"bug-logger": {
"handlers": ["fine-logger1", "fine-logger2", "bugged-logger3"],
"level": logging.DEBUG,
"propagate": True
},
},
}
After it's been setup, if any other handler is setup afterwards (in my case it's the copernicusmarine logger) the handler bugged-logger3 will have a None inside its target field, as every handler that's not incremental will delete existing unused handlers.
I've dug into the source code of logging and I think I've tracked down where this is happpening, but I'm not really sure on how to fix it.
In the config file python3.11/logging/config.py in the configure() function there's a call to _clearExistingHandlers():
else:
disable_existing = config.pop('disable_existing_loggers', True)
_clearExistingHandlers() <-----
# Do formatters first - they don't refer to anything else
formatters = config.get('formatters', EMPTY_DICT)
for name in formatters:
try:
formatters[name] = self.configure_formatter(
formatters[name])
If we comment this line, it works completely fine. But I guess this just keeps handlers loaded in memory and that's not a proper solution.
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans python3.11/logging/config.py, en particulier dans DictConfig.configure() et _clearExistingHandlers(). Reproduisez la configuration fournie, puis configurez un autre logger et vérifiez si MemoryHandler.target devient None. Le travail est terminé lorsqu’une configuration ultérieure non incrémentielle ne casse plus la cible de MemoryHandler, tout en conservant le fonctionnement correct du nettoyage des handlers.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- tooling
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100