保存代碼到文件: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())
網(wǎng)頁標(biāo)題:基于Pythonlog的正確打開方式-創(chuàng)新互聯(lián)
URL鏈接:http://www.chinadenli.net/article42/djdiec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、網(wǎng)站建設(shè)、做網(wǎng)站、定制網(wǎng)站、定制開發(fā)、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)