In Django, I've got loggers all over the place, currently with hard-coded names.
For module-level logging (i.e., in a module of view functions) I have the urge to do this.
log = logging.getLogger(__name__)
For class-level logging (i.e., in a class __init__
method) I have the urge to do this.
self.log = logging.getLogger("%s.%s" % (
self.__module__, self.__class__.__name__))
I'm looking for second opinions before I tackle several dozen occurrences of getLogger("hard.coded.name")
.
Will this work? Anyone else naming their loggers with the same unimaginative ways?
Further, should I break down and write a class decorator for this log definition?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…