1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| logger = logging.getLogger()
logger.setLevel(logging.INFO)
fmt = logging.Formatter('[%(asctime)s][%(filename)s][line:%(lineno)d][%(levelname)s] %(message)s', '%Y-%m-%d %H:%M:%S')
console_handler = logging.StreamHandler(stream=sys.stdout) console_handler.setFormatter(fmt) console_handler.setLevel(logging.INFO) logger.addHandler(console_handler)
file_handler = logging.handlers.RotatingFileHandler(file_path, maxBytes=per_file_size, backupCount=log_file_number) file_handler.setFormatter(fmt) file_handler.setLevel(logging.INFO) logger.addHandler(file_handler)
|