How to log everything into a file using RotatingFileHandler by using logging.conf file?

前端 未结 2 2066
攒了一身酷
攒了一身酷 2021-02-19 02:24

I am trying to use RotatingHandler for our logging purpose in Python. I have kept backup files as 500 which means it will create maximum of 500 files I guess and th

2条回答
  •  遇见更好的自我
    2021-02-19 02:48

    It doesn't print out INFO, DEBUG message into the file somehow.. Any thoughts why it is not working out?

    you don't seem to set a loglevel, so the default (warning) is used

    from http://docs.python.org/2/library/logging.html :

    Note that the root logger is created with level WARNING.

    as for your second question, something like this should do the trick (I haven't tested it, just adapted from my config which is using the TimedRotatingFileHandler):

    [loggers]
    keys=root
    
    [handlers]
    keys=logfile
    
    [formatters]
    keys=logfileformatter
    
    [logger_root]
    level=DEBUG
    handlers=logfile
    
    [formatter_logfileformatter]
    format=%(asctime)s %(name)-12s: %(levelname)s %(message)s
    
    [handler_logfile]
    class=handlers.RotatingFileHandler
    level=NOTSET
    args=('testing.log','a',2000,100)
    formatter=logfileformatter
    

提交回复
热议问题