python-logging

import threading
import time
import logging

FORMAT = "%(asctime)s %(thread)d %(message)s"
FORMATLOG1 ="%(asctime)s %(thread)d %(threadName)s %(message)s"
logging.basicConfig(level=logging.INFO,format=FORMAT,filename="d:/kang.log")


def add(x,y):
logging.info("thread:{},sum:{}".format(threading.enumerate(),x+y))
logging.info("%s,%s",x,y)

t =threading.Thread(target=add,args=(6,2))
t.start()

#loga  =logging.getLogger(__name__)

loga =logging.getLogger('s')
print(loga.getEffectiveLevel())

loga.setLevel(logging.INFO)
loga1 =logging.getLogger('s.s1')

hlr =logging.FileHandler('d:/loghdlr.log') #日志存储
fmt1 =logging.Formatter(fmt=FORMATLOG1) #自己定义格式
hlr.setFormatter(fmt1)
loga1.addHandler(hlr) #把hlr挂到loga1上

loga1.info('loga1 info')
print(loga1.getEffectiveLevel())
posted @ 2020-02-02 11:27  冬日的温暖  阅读(181)  评论(0编辑  收藏  举报