def get_log_handler(self):
"""Configure and return file logging handler."""
path = osp.join(gettempdir(), 'pywebhdfs.log')
level = lg.DEBUG
if 'configuration' in self.config:
configuration = self.config['configuration']
if 'logging' in configuration:
logging_config = configuration['logging']
if 'disable' in logging_config and logging_config['disable'] == True:
return NullHandler()
if 'path' in logging_config:
path = logging_config['path'] # Override default path.
if 'level' in logging_config:
level = getattr(lg, logging_config['level'].upper())
log_handler = TimedRotatingFileHandler(
path,
when='midnight', # Daily backups.
backupCount=5,
encoding='utf-8',
)
fmt = '%(asctime)s\t%(name)-16s\t%(levelname)-5s\t%(message)s'
log_handler.setFormatter(lg.Formatter(fmt))
log_handler.setLevel(level)
return log_handler
评论列表
文章目录