Comment 9 for bug 1029640

Revision history for this message
Aimon Bustardo (aimonb) wrote :

ok this code will reproduce. Note that key was to convert to utf8 before sending to syslog.

# vim: tabstop=4 shiftwidth=4 softtabstop=4
import logging
from logging.handlers import SysLogHandler

# our new audit level
# NOTE(jkoelker) Since we synthesized an audit level, make the logging
# module aware of it so it acts like other levels.
logging.AUDIT = logging.INFO + 1
logging.addLevelName(logging.AUDIT, 'AUDIT')

logger = logging.getLogger()
logger.setLevel(logging.INFO)
facility = getattr(logging.handlers.SysLogHandler, 'LOG_SYSLOG', None)

syslog = logging.handlers.SysLogHandler(address='/dev/log', facility=facility)

formatter = logging.Formatter('%(name)s: %(levelname)s: %(message)s')
syslog.setFormatter(formatter)
logger.addHandler(syslog)
# 'application' code
msg = unicode("TEST LOGER FROM PYTHON", "utf-8")
logger.log(logging.AUDIT, msg)