logging - Python TimedRotatingFileHandler logs to a file and stderr -


i trying include simple logging application using timedrotatingfilehandler. output both designated file , standard error. reduced problem small example:

import logging, logging.handlers import sys  logging.basicconfig(format='%(asctime)s %(message)s') loghandler = logging.handlers.timedrotatingfilehandler("logfile",when="midnight") logger = logging.getlogger() logger.setlevel(logging.info) logger.addhandler(loghandler)  k in range(5):     logger.info("line %d" %  k) 

i 5 log lines both in 'logfile' , program's stderr. doing wrong?

this way can have print on log files , not stdout/stderr:

import logging logging.handlers import timedrotatingfilehandler  loghandler = timedrotatingfilehandler("logfile",when="midnight") logformatter = logging.formatter('%(asctime)s %(message)s') loghandler.setformatter( logformatter ) logger = logging.getlogger( 'mylogger' ) logger.addhandler( loghandler ) logger.setlevel( logging.info )  k in range(5):     logger.info("line %d" %  k) 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -