class logging.handlers.SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM)
Returns a new instance of the SysLogHandler class intended to communicate with a remote Unix machine whose address is given by address in the form of a (host, port) tuple. If address is not specified, ('localhost', 514) is used. The address is used to open a socket. An alternative to providing a (host, port) tuple is providing an address as a string, for example ‘/dev/log’. In this case, a Unix domain socket is used to send the message to the syslog. If facility is not specified, LOG_USER is used. The type of socket opened depends on the socktype argument, which defaults to socket.SOCK_DGRAM and thus opens a UDP socket. To open a TCP socket (for use with the newer syslog daemons such as rsyslog), specify a value of socket.SOCK_STREAM.
Note that if your server is not listening on UDP port 514, SysLogHandler may appear not to work. In that case, check what address you should be using for a domain socket - it’s system dependent. For example, on Linux it’s usually ‘/dev/log’ but on OS/X it’s ‘/var/run/syslog’. You’ll need to check your platform and use the appropriate address (you may need to do this check at runtime if your application needs to run on several platforms). On Windows, you pretty much have to use the UDP option.
Changed in version 3.2: socktype was added.
-
close() -
Closes the socket to the remote host.
-
emit(record) -
The record is formatted, and then sent to the syslog server. If exception information is present, it is not sent to the server.
Changed in version 3.2.1: (See: issue 12168.) In earlier versions, the message sent to the syslog daemons was always terminated with a NUL byte, because early versions of these daemons expected a NUL terminated message - even though it’s not in the relevant specification (RFC 5424). More recent versions of these daemons don’t expect the NUL byte but strip it off if it’s there, and even more recent daemons (which adhere more closely to RFC 5424) pass the NUL byte on as part of the message.
To enable easier handling of syslog messages in the face of all these differing daemon behaviours, the appending of the NUL byte has been made configurable, through the use of a class-level attribute,
append_nul. This defaults toTrue(preserving the existing behaviour) but can be set toFalseon aSysLogHandlerinstance in order for that instance to not append the NUL terminator.Changed in version 3.3: (See: issue 12419.) In earlier versions, there was no facility for an “ident” or “tag” prefix to identify the source of the message. This can now be specified using a class-level attribute, defaulting to
""to preserve existing behaviour, but which can be overridden on aSysLogHandlerinstance in order for that instance to prepend the ident to every message handled. Note that the provided ident must be text, not bytes, and is prepended to the message exactly as is.
-
encodePriority(facility, priority) -
Encodes the facility and priority into an integer. You can pass in strings or integers - if strings are passed, internal mapping dictionaries are used to convert them to integers.
The symbolic
LOG_values are defined inSysLogHandlerand mirror the values defined in thesys/syslog.hheader file.Priorities
Name (string) Symbolic value alertLOG_ALERT critorcriticalLOG_CRIT debugLOG_DEBUG emergorpanicLOG_EMERG errorerrorLOG_ERR infoLOG_INFO noticeLOG_NOTICE warnorwarningLOG_WARNING Facilities
Name (string) Symbolic value authLOG_AUTH authprivLOG_AUTHPRIV cronLOG_CRON daemonLOG_DAEMON ftpLOG_FTP kernLOG_KERN lprLOG_LPR mailLOG_MAIL newsLOG_NEWS syslogLOG_SYSLOG userLOG_USER uucpLOG_UUCP local0LOG_LOCAL0 local1LOG_LOCAL1 local2LOG_LOCAL2 local3LOG_LOCAL3 local4LOG_LOCAL4 local5LOG_LOCAL5 local6LOG_LOCAL6 local7LOG_LOCAL7
-
mapPriority(levelname) -
Maps a logging level name to a syslog priority name. You may need to override this if you are using custom levels, or if the default algorithm is not suitable for your needs. The default algorithm maps
DEBUG,INFO,WARNING,ERRORandCRITICALto the equivalent syslog names, and all other level names to ‘warning’.
Please login to continue.