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

20 Views Asked by At

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 logging
import logging.handlers

def 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_logger

def info_log(sys_logger, message):
    sys_logger.info("MyLogger: %s" % (message))

def error_log(sys_logger, message):
    sys_logger.critical("MyLogger: %s" % (message))

# Setup logger
logger = setup_sys_logger('TestLogger')
print(logger.getEffectiveLevel())

# Log messages
info_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.
0

There are 0 best solutions below