Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
logging.handlers.SysLogHandler Class Reference

List of all members.

Public Member Functions

def __init__
def encodePriority
def close
def mapPriority
def emit

Public Attributes

 address
 facility
 socktype
 unixsocket
 socket
 formatter

Static Public Attributes

int LOG_EMERG = 0
int LOG_ALERT = 1
int LOG_CRIT = 2
int LOG_ERR = 3
int LOG_WARNING = 4
int LOG_NOTICE = 5
int LOG_INFO = 6
int LOG_DEBUG = 7
int LOG_KERN = 0
int LOG_USER = 1
int LOG_MAIL = 2
int LOG_DAEMON = 3
int LOG_AUTH = 4
int LOG_SYSLOG = 5
int LOG_LPR = 6
int LOG_NEWS = 7
int LOG_UUCP = 8
int LOG_CRON = 9
int LOG_AUTHPRIV = 10
int LOG_FTP = 11
int LOG_LOCAL0 = 16
int LOG_LOCAL1 = 17
int LOG_LOCAL2 = 18
int LOG_LOCAL3 = 19
int LOG_LOCAL4 = 20
int LOG_LOCAL5 = 21
int LOG_LOCAL6 = 22
int LOG_LOCAL7 = 23
dictionary priority_names
dictionary facility_names
dictionary priority_map
 append_nul = True

Private Member Functions

def _connect_unixsocket

Detailed Description

A handler class which sends formatted logging records to a syslog
server. Based on Sam Rushing's syslog module:
http://www.nightmare.com/squirl/python-ext/misc/syslog.py
Contributed by Nicolas Untz (after which minor refactoring changes
have been made).

Definition at line 600 of file handlers.py.


Constructor & Destructor Documentation

def logging.handlers.SysLogHandler.__init__ (   self,
  address = ('localhost', SYSLOG_UDP_PORT,
  facility = LOG_USER,
  socktype = socket.SOCK_DGRAM 
)
Initialize a handler.

If address is specified as a string, a UNIX socket is used. To log to a
local syslogd, "SysLogHandler(address="/dev/log")" can be used.
If facility is not specified, LOG_USER is used.

Definition at line 704 of file handlers.py.

00704 
00705                  facility=LOG_USER, socktype=socket.SOCK_DGRAM):
00706         """
00707         Initialize a handler.
00708 
00709         If address is specified as a string, a UNIX socket is used. To log to a
00710         local syslogd, "SysLogHandler(address="/dev/log")" can be used.
00711         If facility is not specified, LOG_USER is used.
00712         """
00713         logging.Handler.__init__(self)
00714 
00715         self.address = address
00716         self.facility = facility
00717         self.socktype = socktype
00718 
00719         if isinstance(address, str):
00720             self.unixsocket = 1
00721             self._connect_unixsocket(address)
00722         else:
00723             self.unixsocket = 0
00724             self.socket = socket.socket(socket.AF_INET, socktype)
00725             if socktype == socket.SOCK_STREAM:
00726                 self.socket.connect(address)
00727         self.formatter = None

Here is the caller graph for this function:


Member Function Documentation

def logging.handlers.SysLogHandler._connect_unixsocket (   self,
  address 
) [private]

Definition at line 728 of file handlers.py.

00728 
00729     def _connect_unixsocket(self, address):
00730         self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
00731         # syslog may require either DGRAM or STREAM sockets
00732         try:
00733             self.socket.connect(address)
00734         except socket.error:
00735             self.socket.close()
00736             self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
00737             self.socket.connect(address)

Here is the caller graph for this function:

Closes the socket.

Definition at line 751 of file handlers.py.

00751 
00752     def close (self):
00753         """
00754         Closes the socket.
00755         """
00756         if self.unixsocket:
00757             self.socket.close()
00758         logging.Handler.close(self)

Here is the caller graph for this function:

def logging.handlers.SysLogHandler.emit (   self,
  record 
)
Emit a record.

The record is formatted, and then sent to the syslog server. If
exception information is present, it is NOT sent to the server.

Definition at line 771 of file handlers.py.

00771 
00772     def emit(self, record):
00773         """
00774         Emit a record.
00775 
00776         The record is formatted, and then sent to the syslog server. If
00777         exception information is present, it is NOT sent to the server.
00778         """
00779         msg = self.format(record)
00780         if self.append_nul:
00781             msg += '\000'
00782         """
00783         We need to convert record level to lowercase, maybe this will
00784         change in the future.
00785         """
00786         prio = '<%d>' % self.encodePriority(self.facility,
00787                                             self.mapPriority(record.levelname))
00788         prio = prio.encode('utf-8')
00789         # Message is a string. Convert to bytes as required by RFC 5424
00790         msg = msg.encode('utf-8')
00791         if codecs:
00792             msg = codecs.BOM_UTF8 + msg
00793         msg = prio + msg
00794         try:
00795             if self.unixsocket:
00796                 try:
00797                     self.socket.send(msg)
00798                 except socket.error:
00799                     self._connect_unixsocket(self.address)
00800                     self.socket.send(msg)
00801             elif self.socktype == socket.SOCK_DGRAM:
00802                 self.socket.sendto(msg, self.address)
00803             else:
00804                 self.socket.sendall(msg)
00805         except (KeyboardInterrupt, SystemExit):
00806             raise
00807         except:
00808             self.handleError(record)

Here is the call graph for this function:

def logging.handlers.SysLogHandler.encodePriority (   self,
  facility,
  priority 
)
Encode the facility and priority. You can pass in strings or
integers - if strings are passed, the facility_names and
priority_names mapping dictionaries are used to convert them to
integers.

Definition at line 738 of file handlers.py.

00738 
00739     def encodePriority(self, facility, priority):
00740         """
00741         Encode the facility and priority. You can pass in strings or
00742         integers - if strings are passed, the facility_names and
00743         priority_names mapping dictionaries are used to convert them to
00744         integers.
00745         """
00746         if isinstance(facility, str):
00747             facility = self.facility_names[facility]
00748         if isinstance(priority, str):
00749             priority = self.priority_names[priority]
00750         return (facility << 3) | priority

Here is the caller graph for this function:

def logging.handlers.SysLogHandler.mapPriority (   self,
  levelName 
)
Map a logging level name to a key in the priority_names map.
This is useful in two scenarios: when custom levels are being
used, and in the case where you can't do a straightforward
mapping by lowercasing the logging level name because of locale-
specific issues (see SF #1524081).

Definition at line 759 of file handlers.py.

00759 
00760     def mapPriority(self, levelName):
00761         """
00762         Map a logging level name to a key in the priority_names map.
00763         This is useful in two scenarios: when custom levels are being
00764         used, and in the case where you can't do a straightforward
00765         mapping by lowercasing the logging level name because of locale-
00766         specific issues (see SF #1524081).
00767         """
00768         return self.priority_map.get(levelName, "warning")

Here is the caller graph for this function:


Member Data Documentation

Definition at line 714 of file handlers.py.

Definition at line 769 of file handlers.py.

Definition at line 715 of file handlers.py.

Initial value:
{
        "auth":     LOG_AUTH,
        "authpriv": LOG_AUTHPRIV,
        "cron":     LOG_CRON,
        "daemon":   LOG_DAEMON,
        "ftp":      LOG_FTP,
        "kern":     LOG_KERN,
        "lpr":      LOG_LPR,
        "mail":     LOG_MAIL,
        "news":     LOG_NEWS,
        "security": LOG_AUTH,       #  DEPRECATED
        "syslog":   LOG_SYSLOG,
        "user":     LOG_USER,
        "uucp":     LOG_UUCP,
        "local0":   LOG_LOCAL0,
        "local1":   LOG_LOCAL1,
        "local2":   LOG_LOCAL2,
        "local3":   LOG_LOCAL3,
        "local4":   LOG_LOCAL4,
        "local5":   LOG_LOCAL5,
        "local6":   LOG_LOCAL6,
        "local7":   LOG_LOCAL7,
        }

Definition at line 667 of file handlers.py.

Definition at line 726 of file handlers.py.

Definition at line 620 of file handlers.py.

Definition at line 633 of file handlers.py.

Definition at line 639 of file handlers.py.

Definition at line 621 of file handlers.py.

Definition at line 638 of file handlers.py.

Definition at line 632 of file handlers.py.

Definition at line 626 of file handlers.py.

Definition at line 619 of file handlers.py.

Definition at line 622 of file handlers.py.

Definition at line 640 of file handlers.py.

Definition at line 625 of file handlers.py.

Definition at line 629 of file handlers.py.

Definition at line 643 of file handlers.py.

Definition at line 644 of file handlers.py.

Definition at line 645 of file handlers.py.

Definition at line 646 of file handlers.py.

Definition at line 647 of file handlers.py.

Definition at line 648 of file handlers.py.

Definition at line 649 of file handlers.py.

Definition at line 650 of file handlers.py.

Definition at line 635 of file handlers.py.

Definition at line 631 of file handlers.py.

Definition at line 636 of file handlers.py.

Definition at line 624 of file handlers.py.

Definition at line 634 of file handlers.py.

Definition at line 630 of file handlers.py.

Definition at line 637 of file handlers.py.

Definition at line 623 of file handlers.py.

Initial value:
{
        "DEBUG" : "debug",
        "INFO" : "info",
        "WARNING" : "warning",
        "ERROR" : "error",
        "CRITICAL" : "critical"
    }

Definition at line 695 of file handlers.py.

Initial value:
{
        "alert":    LOG_ALERT,
        "crit":     LOG_CRIT,
        "critical": LOG_CRIT,
        "debug":    LOG_DEBUG,
        "emerg":    LOG_EMERG,
        "err":      LOG_ERR,
        "error":    LOG_ERR,        #  DEPRECATED
        "info":     LOG_INFO,
        "notice":   LOG_NOTICE,
        "panic":    LOG_EMERG,      #  DEPRECATED
        "warn":     LOG_WARNING,    #  DEPRECATED
        "warning":  LOG_WARNING,
        }

Definition at line 652 of file handlers.py.

Definition at line 723 of file handlers.py.

Definition at line 716 of file handlers.py.

Definition at line 719 of file handlers.py.


The documentation for this class was generated from the following file: