logger示例
Posted 风-fmgao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logger示例相关的知识,希望对你有一定的参考价值。
胜哥版
#!/usr/bin/env python
# encoding: utf-8
# Date: 2018/5/27
import logging
def get_logger(name):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
fh = logging.FileHandler(‘atm.log‘)
logger.addHandler(ch)
logger.addHandler(fh)
file_formatter = logging.Formatter(‘%(asctime)s - %(name)s - %(levelname)s - %(message)s‘)
console_formatter = logging.Formatter(‘%(asctime)s - %(name)s - %(levelname)s - %(lineno)d - %(message)s‘)
ch.setFormatter(console_formatter)
fh.setFormatter(file_formatter)
return logger
调用:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2018/5/28 16:23
# @File : test_logger.py
from logger_demo import get_logger
logger = get_logger(‘atm‘)
logger.info(‘test‘)
logger = get_logger(‘shopping‘)
logger.info(‘shopping test‘)
以上是关于logger示例的主要内容,如果未能解决你的问题,请参考以下文章
csharp C#超级简单记录器类//用法示例:https://heiswayi.nrird.com/2016/creating-super-simple-logger-class-in-csharp