Currently you're configuring two file loggers that point to the same logfile
. To only use the RotatingFileHandler
, get rid of the basicConfig
call:
logger = logging.getLogger()
handler = logging.handlers.RotatingFileHandler(logfile, maxBytes=2000000,
backupCount=5)
formatter = logging.Formatter(fmt='%(asctime)s %(name)s %(levelname)s %(message)s',
datefmt='%y%m%d-%H:%M:%S')
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)
All basicConfig
does for you is to provide an easy way to instantiate either a StreamHandler
(default) or a FileHandler
and set its loglevel and formats (see the docs for more information). If you need a handler other than these two, you should instantiate and configure it yourself.