1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- # -*- coding: utf-8 -*-
- import logging
- import os
- import datetime
- import sys
- def info(str):
- script_path = os.path.split(os.path.realpath(__file__))[0]
- nowTime = datetime.datetime.now().strftime('%Y%m%d')
- path = os.path.join(script_path + r'\logs', 'info_' + nowTime + ".log")
- isExists = os.path.exists(script_path + r'\logs')
- if not isExists:
- os.makedirs(script_path + r'\logs')
- logger = logging.getLogger("run")
- logger.setLevel(level=logging.INFO)
- handler = logging.FileHandler(path)
- handler.setLevel(logging.INFO)
- formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s => %(message)s')
- handler.setFormatter(formatter)
- logger.addHandler(handler)
- logger.info(str)
- logger.removeHandler(handler)
- def warning(str):
- script_path = os.path.split(os.path.realpath(__file__))[0]
- nowTime = datetime.datetime.now().strftime('%Y%m%d')
- path = os.path.join(script_path + r'\logs', 'info_' + nowTime + ".log")
- isExists = os.path.exists(script_path + r'\logs')
- if not isExists:
- os.makedirs(script_path + r'\logs')
- logger = logging.getLogger("run")
- logger.setLevel(level=logging.WARNING)
- handler = logging.FileHandler(path)
- handler.setLevel(logging.WARNING)
- formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s => %(message)s')
- handler.setFormatter(formatter)
- logger.addHandler(handler)
- logger.warning(str)
- logger.removeHandler(handler)
- def error(str):
- script_path = os.path.split(os.path.realpath(__file__))[0]
- nowTime = datetime.datetime.now().strftime('%Y%m%d')
- path = os.path.join(script_path + r'\logs', 'error_' + nowTime + ".log")
- isExists = os.path.exists(script_path + r'\logs')
- if not isExists:
- os.makedirs(script_path + r'\logs')
- logger = logging.getLogger("run")
- logger.setLevel(level=logging.ERROR)
- handler = logging.FileHandler(path)
- handler.setLevel(logging.ERROR)
- formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s => %(message)s')
- handler.setFormatter(formatter)
- logger.addHandler(handler)
- logger.error(str)
- logger.removeHandler(handler)
|