strange behavior of logger

Alex

I encountered such a problem and couldn't solve it. I used python's logger to log info, logger level set to logging.DEBUG. I used gunicorn to log info at the same time. Normally, the error message goes to python's logger, and the link messages and other messages written by logger.info or logger.debug goes to the log file of gunicorn. However with one application it doesn't behave so. The messages output by logger.info also goes to python's logger. The problem is, I only want to see error messages in python's logger, all the other messages would be seen from gunicorn's logger. Can anyone give me a clue where I might do wrong in this situation?

thx in advance, alex

The following is my config:

LOGGER_LEVEL = logging.DEBUG  
LOGGER_ROOT_NAME = "root"  
LOGGER_ROOT_HANLDERS = [logging.StreamHandler, logging.FileHandler]  
LOGGER_ROOT_LEVEL = LOGGER_LEVEL  
LOGGER_ROOT_FORMAT = "[%(asctime)s %(levelname)s %(name)s %(funcName)s:%(lineno)d] %(message)s"  
LOGGER_LEVEL = logging.ERROR  
LOGGER_FILE_PATH = "/data/log/web/"  

Code:

def config_root_logger(self):
    formatter = logging.Formatter(self.config.LOGGER_ROOT_FORMAT)

    logger = logging.getLogger()
    logger.setLevel(self.config.LOGGER_ROOT_LEVEL)

    filename = os.path.join(self.config.LOGGER_FILE_PATH, "secondordersrv.log")
    handler = logging.FileHandler(filename)
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    # 测试环境配置再增加console的日志记录
    self._add_test_handler(logger, formatter)

def _add_test_handler(self, logger, formatter):
    # 测试环境配置再增加console的日志记录
    if self.config.RUN_MODE == 'test':
        handler = logging.StreamHandler()
        handler.setFormatter(formatter)
        logger.addHandler(handler)

My gunicorn config looks like this:

errorlog = '/data/log/web/%s.log' % APP_NAME  
loglevel = 'info'  
accesslog = '-'
minghan

You did not set the level of your handler.

After handler.setFormatter(formatter), add the following line:

handler.setLevel(self.config.LOGGER_LEVEL)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related