import logging def init_logger(): logger = logging.getLogger() # get the root logger logger.setLevel(logging.DEBUG) handler = logging.StreamHandler() handler.setLevel(logging.DEBUG) formatter = logging.Formatter("[%(levelname)s] %(message)s") handler.setFormatter(formatter) logger.addHandler(handler) trace_handler = logging.FileHandler("trace.log", "w") trace_handler.setLevel(logging.INFO) # trace_formatter = logging.Formatter("%(asctime)s[%(levelname)s],%(message)s") trace_formatter = logging.Formatter("%(message)s") trace_handler.setFormatter(trace_formatter) logger.addHandler(trace_handler)