41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
# coding=utf-8
|
|
import os
|
|
import sys
|
|
import logging
|
|
|
|
|
|
class Logger:
|
|
def __init__(self, log_file):
|
|
self.logger = logging.getLogger(__name__)
|
|
self.logger.setLevel(logging.DEBUG)
|
|
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
|
file_handler = logging.FileHandler(log_file)
|
|
file_handler.setLevel(logging.DEBUG)
|
|
file_handler.setFormatter(formatter)
|
|
self.logger.addHandler(file_handler)
|
|
|
|
def log(self, message):
|
|
self.logger.info(message)
|
|
|
|
def error(self, message):
|
|
self.logger.error(message)
|
|
|
|
def warning(self, message):
|
|
self.logger.warning(message)
|
|
|
|
def debug(self, message):
|
|
self.logger.debug(message)
|
|
|
|
# 关闭日志
|
|
def close(self):
|
|
self.logger.removeHandler(self.logger.handlers[0])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logger = Logger('log/TestLog.log')
|
|
logger.log(u'################ SdeSynchronous ################\n\n')
|
|
logger.log(u"输出增量MDO完成")
|
|
logger.error(u"输出层信息失败!")
|
|
logger.warning(u"信息不对等,请注意!")
|
|
logger.debug(u"这里的数值是1")
|