When using the python logging module, how do I specify the file name of the automatically generated log when installing the size cut?

topic description

when using the python logging module, how do I specify the file name of the automatically generated log when installing the size cut?

< hr >
logger = logging.getLogger("mylogger")
logger.setLevel(level=logger_level)
fmt = "%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s"
format_str = logging.Formatter(fmt)
fh = logging.FileHandler(fn, encoding="utf-8")
fh = logging.handlers.RotatingFileHandler(fn,maxBytes=10000,backupCount=10)
fh.setFormatter(fmt=format_str)
logger.addHandler(fh)

when using RotatingFileHandler , how can I customize the filename of the "log.1"-like file that it automatically generates?

Aug.24,2021

RotatingFileHandler inherits from the BaseRotatingHandler class, and has the following method

   
pre-and post-modified file names, mylog and backup

Menu