Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16420

Python logging to Syslog: only ERROR level messages appear in syslog

$
0
0

I'm encountering an issue with python’s logging module. Although I've configured it to log messages at various levels, only logs with the ERROR level are being recorded in the syslog. Logs at the INFO and DEBUG levels aren't appearing. What am I missing?

import loggingimport logging.handlersdef setup_sys_logger(app_name):    sys_logger = logging.getLogger(app_name)    sys_handler = logging.handlers.SysLogHandler(address="/dev/log")    sys_handler.setLevel(logging.INFO)    sys_logger.setLevel(logging.INFO)  # Ensure the logger processes INFO level and above    sys_logger.addHandler(sys_handler)    return sys_loggerdef info_log(sys_logger, message):    sys_logger.info("MyLogger: %s" % (message))def error_log(sys_logger, message):    sys_logger.critical("MyLogger: %s" % (message))# Setup loggerlogger = setup_sys_logger('TestLogger')print(logger.getEffectiveLevel())# Log messagesinfo_log(logger, "This is a test info message.")error_log(logger, "This is a test error message.")

Response for getEffectiveLevel() is 20

I see only the following message in syslog:

This is a test error message.

Viewing all articles
Browse latest Browse all 16420

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>