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?

5
  • 1
    Please correct the code alignment Commented Nov 13, 2017 at 15:54
  • logger.addHandler(fh) <-- but fh (presumably your file handler) is not defined, I can't see how this would run Commented Nov 13, 2017 at 16:11
  • Sry missed out a bit, updated Commented Nov 13, 2017 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: stackoverflow.com/questions/3968669/… Commented Nov 13, 2017 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. Commented Nov 13, 2017 at 16:38

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.