The ATM-5 of Python basics

Source: Internet
Author: User

Import logging
Import OS
Import Sys
Base_dir = Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))
Sys.path.append (Base_dir)
From conf import settings
From logging import handlers
‘‘‘
This module is the logging module, which realizes the logging of the log
‘‘‘

def write_logger (Log_params,info):
Logger = Logging.getlogger (' Atm_log ')
Logger.setlevel (logging. DEBUG)
Log_path = Log_handler (log_params)
log_file = '%s.log '% (Log_path)
# fh = logging. Filehandler (log_file) #普通
# FH = handlers. Rotatingfilehandler (filename=log_file,maxbytes=10,backupcount=3) #按大小备份
FH = handlers. Timedrotatingfilehandler (Filename=log_file, when= "Midnight", Interval=5, Backupcount=3) #每日凌晨生成一个日志文件, original file backup
Fh.setlevel (logging. DEBUG)
Fh_formatter = logging. Formatter ('% (asctime) s% (levelname) s:% (message) s ')
Fh.setformatter (Fh_formatter)
Logger.addhandler (FH)
Logger.debug (Info)
Logger.removehandler (FH)

def file_log_handler (log_params):
Log_path = '%s\%s '% (log_params["path"],log_params["name"])
Return Log_path

def log_handler (log_params):
If log_params["file"] = = "Data":
Return File_log_handler (Log_params)
elif log_params["file"] = = "Trans":
Return File_log_handler (Log_params)

The ATM-5 of Python basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.