syslog
Options
LOG_PID // log the pid with each message
LOG_CONS // log on the console if errors in sending
LOG_NDELAY // don't delay open
LOG_NOWAIT // don't wait for console forks: DEPRECATED
LOG_PERROR // log to stderr as well
Facilities
LOG_KERN // kernel messages
LOG_USER // random user-level messages
LOG_MAIL // mail system
LOG_DAEMON // system daemons
LOG_AUTH // security/authorization messages
LOG_SYSLOG // messages generated internally by syslogd
LOG_LPR // line printer subsystem
LOG_NEWS // network news subsystem
LOG_UUCP // UUCP subsystem
LOG_CRON // clock daemon
LOG_LOCAL0 // reserved for local use
LOG_LOCAL1 // reserved for local use
LOG_LOCAL2 // reserved for local use
LOG_LOCAL3 // reserved for local use
LOG_LOCAL4 // reserved for local use
LOG_LOCAL5 // reserved for local use
LOG_LOCAL6 // reserved for local use
LOG_LOCAL7 // reserved for local use
Priority levels
LOG_EMERG // system is unusable
LOG_ALERT // action must be taken immediately
LOG_CRIT // critical conditions
LOG_ERR // error conditions
LOG_WARNING // warning conditions
LOG_NOTICE // normal but significant condition
LOG_INFO // informational
LOG_DEBUG // debug-level messages
syslog
syslog.syslog(message)
syslog.syslog(priority, message)
Send the string message to the system logger. A trailing newline is added if necessary. Each message is tagged with a priority composed of a facility and a level. The optional priority argument, which defaults to LOG_INFO, determines the message priority. If the facility is not encoded in priority using logical-or (LOG_INFO LOG_USER), the value given in the openlog() call is used.
If openlog() has not been called prior to the call to syslog(), openlog() will be called with no arguments.
openlog
syslog.openlog([ident[, logoption[, facility]]])
Logging options of subsequent syslog() calls can be set by calling openlog(). syslog() will call openlog() with no arguments if the log is not currently open.
The optional ident keyword argument is a string which is prepended to every message, and defaults to sys.argv[0] with leading path components stripped. The optional logoption keyword argument (default is 0) is a bit field – see below for possible values to combine. The optional facility keyword argument (default is LOG_USER) sets the default facility for messages which do not have a facility explicitly encoded.
closelog
syslog.closelog()
Reset the syslog module values and call the system library closelog().
This causes the module to behave as it does when initially imported. For example, openlog() will be called on the first syslog() call (if openlog() hasn’t already been called), and ident and other openlog() parameters are reset to defaults.
setlogmask
syslog.setlogmask(maskpri)
Set the priority mask to maskpri and return the previous mask value. Calls to syslog() with a priority level not set in maskpri are ignored. The default is to log all priorities. The function LOG_MASK(pri) calculates the mask for the individual priority pri. The function LOG_UPTO(pri) calculates the mask for all priorities up to and including pri.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import syslog
def log():
"""
syslog example
"""
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
string = "Hello World."
syslog.syslog(syslog.LOG_LOCAL1 | syslog.LOG_WARNING, string)
syslog.closelog()
def main():
log()
if __name__ == "__main__":
main()