python logging to syslog linux 1

python logging to syslog linux

import logging
import logging.handlers

my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)

handler = logging.handlers.SysLogHandler(address = '/dev/log')

my_logger.addHandler(handler)

my_logger.debug('this is debug')
my_logger.critical('this is critical')

Here is what the above code is Doing:
1. Create a logger object
2. Set the level of the logger to DEBUG
3. Create a handler object
4. Add the handler to the logger
5. Log some messages

Similar Posts