Python logging and rotating files

后端 未结 4 1526
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 06:09

I have a python program that is writing to a log file that is being rotated by Linux\'s logrotate command. When this happens I need to signal my program to stop writing to

4条回答
  •  醉梦人生
    2020-12-14 07:03

    from logging import handlers
    
    handler = handlers.TimedRotatingFileHandler(filename, when=LOG_ROTATE)
    
    handler.setFormatter(logging.Formatter(log_format, datefmt="%d-%m-%Y %H:%M:%S"))
    
    #LOG_ROTATE = midnight    
    #set your log format
    

    This should help you in handling rotating log

提交回复
热议问题