保存代碼到文件:logger.py
成都網(wǎng)絡公司-成都網(wǎng)站建設公司創(chuàng)新互聯(lián)十載經(jīng)驗成就非凡,專業(yè)從事網(wǎng)站建設、成都做網(wǎng)站,成都網(wǎng)頁設計,成都網(wǎng)頁制作,軟文營銷,廣告投放等。十載來已成功提供全面的成都網(wǎng)站建設方案,打造行業(yè)特色的成都網(wǎng)站建設案例,建站熱線:028-86922220,我們期待您的來電!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())