syslog
— Unix syslog library routines¶
This module provides an interface to the Unixsyslog
library routines.Refer to the Unix manual pages for a detailed description of thesyslog
facility.
Διαθεσιμότητα: Unix, not WASI, not iOS.
This module wraps the systemsyslog
family of routines. A pure Pythonlibrary that can speak to a syslog server is available in thelogging.handlers
module asSysLogHandler
.
The module defines the following functions:
- syslog.syslog(message)¶
- syslog.syslog(priority,message)
Send the stringmessage to the system logger. A trailing newline is addedif necessary. Each message is tagged with a priority composed of afacility and alevel. The optionalpriority argument, which defaultsto
LOG_INFO
, determines the message priority. If the facility isnot encoded inpriority using logical-or (LOG_INFO|LOG_USER
), thevalue given in theopenlog()
call is used.If
openlog()
has not been called prior to the call tosyslog()
,openlog()
will be called with no arguments.Raises anauditing event
syslog.syslog
with argumentspriority
,message
.Άλλαξε στην έκδοση 3.2:In previous versions,
openlog()
would not be called automatically ifit wasn’t called prior to the call tosyslog()
, deferring to the syslogimplementation to callopenlog()
.Άλλαξε στην έκδοση 3.12:This function is restricted in subinterpreters.(Only code that runs in multiple interpreters is affected andthe restriction is not relevant for most users.)
openlog()
must be called in the main interpreter beforesyslog()
may be usedin a subinterpreter. Otherwise it will raiseRuntimeError
.
- syslog.openlog([ident[,logoption[,facility]]])¶
Logging options of subsequent
syslog()
calls can be set by callingopenlog()
.syslog()
will callopenlog()
with no argumentsif the log is not currently open.The optionalident keyword argument is a string which is prepended to everymessage, and defaults to
sys.argv[0]
with leading path componentsstripped. The optionallogoption keyword argument (default is 0) is a bitfield – see below for possible values to combine. The optionalfacilitykeyword argument (default isLOG_USER
) sets the default facility formessages which do not have a facility explicitly encoded.Raises anauditing event
syslog.openlog
with argumentsident
,logoption
,facility
.Άλλαξε στην έκδοση 3.2:In previous versions, keyword arguments were not allowed, andident wasrequired.
Άλλαξε στην έκδοση 3.12:This function is restricted in subinterpreters.(Only code that runs in multiple interpreters is affected andthe restriction is not relevant for most users.)This may only be called in the main interpreter.It will raise
RuntimeError
if called in a subinterpreter.
- 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. Forexample,
openlog()
will be called on the firstsyslog()
call (ifopenlog()
hasn’t already been called), andident and otheropenlog()
parameters are reset to defaults.Raises anauditing event
syslog.closelog
with no arguments.Άλλαξε στην έκδοση 3.12:This function is restricted in subinterpreters.(Only code that runs in multiple interpreters is affected andthe restriction is not relevant for most users.)This may only be called in the main interpreter.It will raise
RuntimeError
if called in a subinterpreter.
- syslog.setlogmask(maskpri)¶
Set the priority mask tomaskpri and return the previous mask value. Callsto
syslog()
with a priority level not set inmaskpri are ignored.The default is to log all priorities. The functionLOG_MASK(pri)
calculates the mask for the individual prioritypri. The functionLOG_UPTO(pri)
calculates the mask for all priorities up to and includingpri.Raises anauditing event
syslog.setlogmask
with argumentmaskpri
.
The module defines the following constants:
- syslog.LOG_EMERG¶
- syslog.LOG_ALERT¶
- syslog.LOG_CRIT¶
- syslog.LOG_ERR¶
- syslog.LOG_WARNING¶
- syslog.LOG_NOTICE¶
- syslog.LOG_INFO¶
- syslog.LOG_DEBUG¶
Priority levels (high to low).
- syslog.LOG_AUTH¶
- syslog.LOG_AUTHPRIV¶
- syslog.LOG_CRON¶
- syslog.LOG_DAEMON¶
- syslog.LOG_FTP¶
- syslog.LOG_INSTALL¶
- syslog.LOG_KERN¶
- syslog.LOG_LAUNCHD¶
- syslog.LOG_LPR¶
- syslog.LOG_MAIL¶
- syslog.LOG_NETINFO¶
- syslog.LOG_NEWS¶
- syslog.LOG_RAS¶
- syslog.LOG_REMOTEAUTH¶
- syslog.LOG_SYSLOG¶
- syslog.LOG_USER¶
- syslog.LOG_UUCP¶
- syslog.LOG_LOCAL0¶
- syslog.LOG_LOCAL1¶
- syslog.LOG_LOCAL2¶
- syslog.LOG_LOCAL3¶
- syslog.LOG_LOCAL4¶
- syslog.LOG_LOCAL5¶
- syslog.LOG_LOCAL6¶
- syslog.LOG_LOCAL7¶
Facilities, depending on availability in
<syslog.h>
forLOG_AUTHPRIV
,LOG_FTP
,LOG_NETINFO
,LOG_REMOTEAUTH
,LOG_INSTALL
andLOG_RAS
.Άλλαξε στην έκδοση 3.13:Added
LOG_FTP
,LOG_NETINFO
,LOG_REMOTEAUTH
,LOG_INSTALL
,LOG_RAS
, andLOG_LAUNCHD
.
- syslog.LOG_PID¶
- syslog.LOG_CONS¶
- syslog.LOG_NDELAY¶
- syslog.LOG_ODELAY¶
- syslog.LOG_NOWAIT¶
- syslog.LOG_PERROR¶
Log options, depending on availability in
<syslog.h>
forLOG_ODELAY
,LOG_NOWAIT
andLOG_PERROR
.
Examples¶
Simple example¶
A simple set of examples:
importsyslogsyslog.syslog('Processing started')iferror:syslog.syslog(syslog.LOG_ERR,'Processing started')
An example of setting some log options, these would include the process ID inlogged messages, and write the messages to the destination facility used formail logging:
syslog.openlog(logoption=syslog.LOG_PID,facility=syslog.LOG_MAIL)syslog.syslog('E-mail processing initiated...')