Python Learning Notes (i)--Python encapsulates logging __python

Source: Internet
Author: User

The

Simply encapsulates the code that uses the logging log in Python.
When used:
Logger = Log ("Debuglog")
Logger.error ()
Logger.info ()

#Python记录日志 Import Logging import Time RQ = Time.strftime ('%y%m%d ', Time.localtime (Time.time ())) setting = {' L Ogpath ': '/xxx/xxx/logs/', ' filename ': ' xxx_ ' + RQ + '. Log '} class log (object): "' Def  __init__ (self, name): Self.path = setting[' LogPath '] self.filename = setting[' filename '] self.name = IP Self.logger = Logging.getlogger (self.name) self.logger.setLevel (logging.info) self.fh = Logg Ing. Filehandler (Self.path + self.filename) self.fh.setLevel (logging. DEBUG) Self.formatter = logging. Formatter ('% (asctime) s-% (levelname) s-% (threadname) s-% (name) s-% (message) s ') Self.fh.setFormatter (Self.forma tter) Self.logger.addHandler (SELF.FH) def info (self, msg): Self.logger.info (msg) def warning (sel F, msg): Self.logger.warning (MSG) def error (self, msg): Self.logger.error (MSG) def debug (self, M SG): Self.logger.debug(MSG) def close (self): Self.logger.removeHandler (SELF.FH) 

'

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.