创建⽇志的两种⽅式⽅式⼀:
钟汉良张定涵
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#coding=utf-8
import logging
import os
北京表演学校class Logger(object):
"""
封装好的Logger⼯具
"""
def __init__(self, logPath):
"""
initial
于毅老婆"""
log_path = logPath
logging.addLevelName(20, "NOTICE:")
logging.addLevelName(30, "WARNING:")
logging.addLevelName(40, "FATAL:")
logging.addLevelName(50, "FATAL:")
logging.basicConfig(level=logging.DEBUG,
format="%(levelname)s %(asctime)s [pid:%(process)s] %(filename)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S",
filename=log_path,
filemode="a")
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(levelname)s [pid:%(process)s] %(message)s") console.setFormatter(formatter)
def debug(self, msg=""):
"""
output DEBUG level LOG
"""
logging.debug(str(msg))
def info(self, msg=""):
"""
output INFO level LOG
"""
logging.info(str(msg))大碗宽面歌词
def warning(self, msg=""):
"""
output WARN level LOG
"""
logging.warning(str(msg))
def exception(self, msg=""):
"""
output Exception stack LOG
"""
def error(self, msg=""):
"""
output ERROR level LOG
"""
<(str(msg))
鸿蒙系统怎么升级
def critical(self, msg=""):
"""
output FATAL level LOG
"""
if __name__ == "__main__":
testlog = Logger("oupput.log")
testlog.info("")
testlog.warning("")
try:
lists = []
print lists[1]
except Exception as ex:
"""ption()输出格式:
FATAL: [pid:7776] execute task failed. the exception as follows: Traceback (most recent call last):
File "logtool.py", line 86, in <module>
print lists[1]
IndexError: list index out of range
"""
强心脏崔始源ption("execute task failed. the exception as follows:") testlog.info("++++++++++++++++++++++++++++++++++++++++++++++") """()输出格式:
FATAL: [pid:7776] execute task failed. the exception as follows:
"""
<("execute task failed. the exception as follows:")
exit(1)
⽅式⼆:
os.system("python 123.py > changip.log")