0

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?

Andy
  • 49
  • 2
  • 11
  • 1
    Please correct the code alignment – Sreeram TP Nov 13 '17 at 15:54
  • `logger.addHandler(fh)` <-- but `fh` (presumably your file handler) is not defined, I can't see how this would run – Alex Forbes Nov 13 '17 at 16:11
  • Sry missed out a bit, updated – Andy Nov 13 '17 at 16:14
  • I'm still a bit confused by this. Are you trying to log to the file using rsyslog or python? A syslog filter isn't going to do anything if Python is writing the file. What you might want is a syslog handler: https://stackoverflow.com/questions/3968669/how-to-configure-logging-to-syslog-in-python#3969772 – Alex Forbes Nov 13 '17 at 16:20
  • Truthfully this isn't all the code. What I am trying to do here is send the message to rsyslog through the local6 facility which will the send INFO level messages to a separate file. – Andy Nov 13 '17 at 16:38

1 Answers1

0

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.

Andy
  • 49
  • 2
  • 11