标签:date console _for inf atm env log return OLE
胜哥版
#!/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‘)
标签:date console _for inf atm env log return OLE
原文地址:https://www.cnblogs.com/fmgao-technology/p/9100788.html