创建⽇志的两种⽅式⽅式⼀:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#coding=utf-8
import logging
import osqq怎么私发所有人
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
"""
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")
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论