I try to use logging in Python to write some log, but strangely, only the error will be logged, the info will be ignored no matter whichn level I set.
code:
import logging import logging.handlers if __name__ == "__main__": logger = logging.getLogger() fh = logging.handlers.RotatingFileHandler('./logtest.log', maxBytes=10240, backupCount=5) fh.setLevel(logging.DEBUG)#no matter what level I set here formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) logger.addHandler(fh) logger.info('INFO') logger.error('ERROR') The result is:
2014-01-14 11:47:38,990 - root - ERROR - ERROR According to http://docs.python.org/2/library/logging.html#logging-levels
The INFO should be logged too.