Package logging :: Module handlers :: Class SysLogHandler
[show private | hide private]
[frames | no frames]

Class SysLogHandler

Filterer --+    
           |    
     Handler --+
               |
              SysLogHandler


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).
Method Summary
  __init__(self, address, facility)
Initialize a handler.
  close(self)
Closes the socket.
  emit(self, record)
Emit a record.
  encodePriority(self, facility, priority)
Encode the facility and priority.
  _connect_unixsocket(self, address)
    Inherited from Handler
  acquire(self)
Acquire the I/O thread lock.
  createLock(self)
Acquire a thread lock for serializing access to the underlying I/O.
  flush(self)
Ensure all logging output has been flushed.
  format(self, record)
Format the specified record.
  handle(self, record)
Conditionally emit the specified logging record.
  handleError(self, record)
Handle errors which occur during an emit() call.
  release(self)
Release the I/O thread lock.
  setFormatter(self, fmt)
Set the formatter for this handler.
  setLevel(self, level)
Set the logging level of this handler.
    Inherited from Filterer
  addFilter(self, filter)
Add the specified filter to this handler.
  filter(self, record)
Determine if a record is loggable by consulting all the filters.
  removeFilter(self, filter)
Remove the specified filter from this handler.

Class Variable Summary
dict facility_names = {'kern': 0, 'daemon': 3, 'uucp': 8, 'lo...
int LOG_ALERT = 1                                                                     
int LOG_AUTH = 4                                                                     
int LOG_AUTHPRIV = 10                                                                    
int LOG_CRIT = 2                                                                     
int LOG_CRON = 9                                                                     
int LOG_DAEMON = 3                                                                     
int LOG_DEBUG = 7                                                                     
int LOG_EMERG = 0                                                                     
int LOG_ERR = 3                                                                     
str log_format_string = '<%d>%s\x00'
int LOG_INFO = 6                                                                     
int LOG_KERN = 0                                                                     
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                                                                    
int LOG_LPR = 6                                                                     
int LOG_MAIL = 2                                                                     
int LOG_NEWS = 7                                                                     
int LOG_NOTICE = 5                                                                     
int LOG_SYSLOG = 5                                                                     
int LOG_USER = 1                                                                     
int LOG_UUCP = 8                                                                     
int LOG_WARNING = 4                                                                     
dict priority_names = {'info': 6, 'notice': 5, 'err': 3, 'war...

Method Details

__init__(self, address=('localhost', 514), facility=1)
(Constructor)

Initialize a handler.

If address is specified as a string, UNIX socket is used. If facility is not specified, LOG_USER is used.
Overrides:
logging.Handler.__init__

close(self)

Closes the socket.
Overrides:
logging.Handler.close

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.
Overrides:
logging.Handler.emit

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.

_connect_unixsocket(self, address)


Class Variable Details

facility_names

Type:
dict
Value:
{'auth': 4,
 'authpriv': 10,
 'cron': 9,
 'daemon': 3,
 'kern': 0,
 'local0': 16,
 'local1': 17,
 'local2': 18,
...                                                                    

LOG_ALERT

Type:
int
Value:
1                                                                     

LOG_AUTH

Type:
int
Value:
4                                                                     

LOG_AUTHPRIV

Type:
int
Value:
10                                                                    

LOG_CRIT

Type:
int
Value:
2                                                                     

LOG_CRON

Type:
int
Value:
9                                                                     

LOG_DAEMON

Type:
int
Value:
3                                                                     

LOG_DEBUG

Type:
int
Value:
7                                                                     

LOG_EMERG

Type:
int
Value:
0                                                                     

LOG_ERR

Type:
int
Value:
3                                                                     

log_format_string

Type:
str
Value:
'<%d>%s\x00'                                                           

LOG_INFO

Type:
int
Value:
6                                                                     

LOG_KERN

Type:
int
Value:
0                                                                     

LOG_LOCAL0

Type:
int
Value:
16                                                                    

LOG_LOCAL1

Type:
int
Value:
17                                                                    

LOG_LOCAL2

Type:
int
Value:
18                                                                    

LOG_LOCAL3

Type:
int
Value:
19                                                                    

LOG_LOCAL4

Type:
int
Value:
20                                                                    

LOG_LOCAL5

Type:
int
Value:
21                                                                    

LOG_LOCAL6

Type:
int
Value:
22                                                                    

LOG_LOCAL7

Type:
int
Value:
23                                                                    

LOG_LPR

Type:
int
Value:
6                                                                     

LOG_MAIL

Type:
int
Value:
2                                                                     

LOG_NEWS

Type:
int
Value:
7                                                                     

LOG_NOTICE

Type:
int
Value:
5                                                                     

LOG_SYSLOG

Type:
int
Value:
5                                                                     

LOG_USER

Type:
int
Value:
1                                                                     

LOG_UUCP

Type:
int
Value:
8                                                                     

LOG_WARNING

Type:
int
Value:
4                                                                     

priority_names

Type:
dict
Value:
{'alert': 1,
 'crit': 2,
 'critical': 2,
 'debug': 7,
 'emerg': 0,
 'err': 3,
 'error': 3,
 'info': 6,
...