Skip to content

Instantly share code, notes, and snippets.

@vutkin
Forked from sweenzor/logtest.py
Created July 27, 2018 07:43
Show Gist options
  • Select an option

  • Save vutkin/1e16d5378b9dc0b1f9f8fe82c1fb572f to your computer and use it in GitHub Desktop.

Select an option

Save vutkin/1e16d5378b9dc0b1f9f8fe82c1fb572f to your computer and use it in GitHub Desktop.
Writing to syslog with Python's logging library
import logging
import logging.handlers
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address = '/dev/log')
formatter = logging.Formatter('%(module)s.%(funcName)s: %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
def hello():
log.debug('this is debug')
log.critical('this is critical')
if __name__ == '__main__':
hello()
matt@Jenkins:~$ tail -n 2 /var/log/syslog
Feb 9 11:56:19 Jenkins logtest.hello: this is debug
Feb 9 11:56:19 Jenkins logtest.hello: this is critical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment