基于Python log 的正确打开方式
保存代码到文件:logger.py
import os import logbook from logbook.more import ColorizedStderrHandler import smtplib LOG_DIR = os.path.join('log') if not os.path.exists(LOG_DIR): os.makedirs(LOG_DIR) def get_logger(name='test', file_log=False): logbook.set_datetime_format('local') ColorizedStderrHandler(bubble=False).push_application() if file_log: logbook.TimedRotatingFileHandler(os.path.join(LOG_DIR, '%s.log' % name), date_format='%Y%m%d', bubble=True).push_application() return logbook.Logger(name) LOG = get_logger(file_log=True) def send_email(email_conf, message): smtp = smtplib.SMTP() smtp.connect(email_conf['host'], email_conf['port']) smtp.login(email_conf['user'], email_conf['password']) smtp.sendmail(email_conf['fromaddr'], email_conf['recipients'], message.as_string())
使用方法:
from logger import LOG if __name__ == "__main__": LOG.info('Checking %s:%s ...' % (str(date), str(data_type)))
相关推荐
zhuxue 2020-10-14
zhangbingb 2020-09-21
HeronLinuxampARM 2020-09-14
美丽的泡沫 2020-09-08
goodstudy 2020-08-19
luvhl 2020-08-17
littleFatty 2020-08-16
gamestart0 2020-08-15
URML 2020-08-15
sfkong 2020-08-02
82941732 2020-07-27
偏头痛杨 2020-07-18
timewind 2020-07-04
89407707 2020-06-27
xiaoxiaoCNDS 2020-06-26
lyjava 2020-06-26
运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。以上实例中 7、5 和 12 是操作数。关系运算符用于计算结果是否为 true 或者 false。逻辑运算符用于测定变量或值之间的逻辑。
ChaITSimpleLove 2020-06-25
Strongding 2020-06-25