Search code examples
pythonsyslog

Python logging levels with rsyslog


I am trying to filter levels in rsyslog.d/conf files from the python logger but nothing is getting filtered.

import logging
import logging.handlers

if __name__ == "__main__":
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    fh = logging.handlers.RotatingFileHandler('./logtest.log', maxBytes=10240, backupCount=5)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    logger.addHandler(fh)
    logger.info('INFO')
    logger.error('ERROR')

In my conf file I have:

*.=info -/var/log/info.log

But the info logs are not being logged to that file, any ideas why?


Solution

  • This has been solved. The issue did lie with syslog at all, I had issues in my program where is was not logging the levels correctly to the facility.

    Aka: they were all being logged as warnings.