You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When ask Astropy's logger for a child with getChild methos, the logger returns a default python logger (logging.Logger class) and not a proper astropy.logger.AstropyLogger instance. As the following examples shows:
In [1]: from astropy.logger import log
In [2]: log.__class__
Out[2]: astropy.logger.AstropyLogger
In [3]: l = log.getChild('testing_child')
In [4]: l.__class__
Out[4]: logging.Logger
As everything else works with AstropyLogger's record, any message generated by this child logger will raise AttributeError: 'LogRecord' object has no attribute 'origin', since default logger makeRecord do not set the origin attribute as Astropy do. This problem was noticed by @cdeil a long time ago in astropy/package-template#134 .
A reimplementation like the following one (based on _init_log()) should fix this problem, but generate another problem of multiplicity in output.
class AstropyLogger(Logger):
def getChild(self, suffix):
"""
Simple reimplementation of Logger.getChild
"""
if self.root is not self:
suffix = '.'.join((self.name, suffix))
orig_logger_cls = logging.getLoggerClass()
logging.setLoggerClass(AstropyLogger)
try:
log = logging.getLogger(suffix)
log._set_defaults()
finally:
logging.setLoggerClass(orig_logger_cls)
return log
How could we deal with this problem?
The text was updated successfully, but these errors were encountered:
When ask Astropy's logger for a child with
getChild
methos, the logger returns a default python logger (logging.Logger
class) and not a properastropy.logger.AstropyLogger
instance. As the following examples shows:As everything else works with
AstropyLogger
's record, any message generated by this child logger will raiseAttributeError: 'LogRecord' object has no attribute 'origin'
, since default loggermakeRecord
do not set theorigin
attribute as Astropy do. This problem was noticed by @cdeil a long time ago in astropy/package-template#134 .A reimplementation like the following one (based on
_init_log()
) should fix this problem, but generate another problem of multiplicity in output.How could we deal with this problem?
The text was updated successfully, but these errors were encountered: