4
如何自定义Python日志记录的时间格式?
我是Python日志记录包的新手,并计划将其用于我的项目。我想根据自己的喜好定制时间格式。这是我从教程中复制的简短代码: import logging # create logger logger = logging.getLogger("logging_tryout2") logger.setLevel(logging.DEBUG) # create console handler and set level to debug ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) # create formatter formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(message)s") # add formatter to ch ch.setFormatter(formatter) # add ch to logger logger.addHandler(ch) # "application" code logger.debug("debug message") logger.info("info message") logger.warn("warn message") …