def get_a_logger(name):
"""
Read log config from `log.conf` if file is present.
See the `log.conf.example` for a sample.
:param name: string used for naming the logger
"""
cwd = os.getcwd()
log_conf = os.path.join(cwd, CONFIG_FILE)
if os.path.exists(log_conf):
logging.config.fileConfig(log_conf)
log = logging.getLogger(name)
figlet = get_figlet(name)
if figlet:
print(figlet.format(__version__))
log.debug("{} logging was configured using: {}"
.format(name, log_conf))
handlers = logging.getLoggerClass().root.handlers
for h in [h for h in handlers if hasattr(h, 'baseFilename')]:
log.debug("log file: {}".format(h.baseFilename))
else:
lformat = '%(asctime)s: %(name)s.%(levelname)s ' \
'- %(filename)s+%(lineno)d: %(message)s'
logging.basicConfig(format=lformat, level=logging.INFO)
log = logging.getLogger(name)
log.info("Logging was configured using defaults. "
" To change that please use {} .".format(CONFIG_FILE))
return log
评论列表
文章目录