出来的时候,缩进怎麼有问题了?该怎么改?

logging.conf:
---------------------------
# logging.conf

[loggers]
keys=root,test,test2

[handlers]
keys=consoleHandler,rotateFileHandler

[formatters]
keys=simpleFormatter

[formatter_simpleFormatter]
format=[%(asctime)s](%(levelname)s)%(name)s : %(message)s

[logger_root]
level=DEBUG
handlers=consoleHandler,rotateFileHandler

[logger_test]
level=DEBUG
handlers=consoleHandler,rotateFileHandler
qualname=test
propagate=0

[logger_test2]
level=DEBUG
handlers=consoleHandler,rotateFileHandler
qualname=test2
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_rotateFileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('test.log', 'a', 20000, 9)
----------------------------------------------
my_test:
----------------------------------------------
#python33
from tkinter import *
import logging 
import logging.config

def Log(text):
logging.config.fileConfig("logging.conf")

logger = loggong.getLogger("test")

logger.info(text)

def Test():
Log("Test")

if __name__=="__main__":
root = Tk()

btn1 = Button(root, text='test', command=Test)

btn1.grid()

root.mainloop()

慕妹3146593
浏览 85回答 1
1回答

交互式爱情

原生loggging类+  TimedRotatingFileHandler类 实现按day hour second 切分import loggingfrom logging.handlers import TimedRotatingFileHandlerlog = logging.getLogger(loggerName)formatter = logging.Formatter('%(name)-12s %(asctime)s level-%(levelname)-8s thread-%(thread)-8d %(message)s')   # 每行日志的前缀设置fileTimeHandler = TimedRotatingFileHandler(BASIC_LOG_PATH + filename, "S", 1, 10)fileTimeHandler.suffix = "%Y%m%d.log"  #设置 切分后日志文件名的时间格式 默认 filename+"." + suffix 如果需要更改需要改logging 源码fileTimeHandler.setFormatter(formatter)logging.basicConfig(level = logging.INFO)fileTimeHandler.setFormatter(formatter)log.addHandler(fileTimeHandler)try:    log.error(msg)except Exception, e:    print "writeLog error"finally:   log.removeHandler(fileTimeHandler)值 interval的类型S 秒M 分钟H 小时D 天W 周midnight 在午夜
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python