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

Class NTEventLogHandler

Filterer --+    
           |    
     Handler --+
               |
              NTEventLogHandler


A handler class which sends events to the NT Event Log. Adds a registry entry for the specified application name. If no dllname is provided, win32service.pyd (which contains some basic message placeholders) is used. Note that use of these placeholders will make your event logs big, as the entire message source is held in the log. If you want slimmer logs, you have to pass in the name of your own DLL which contains the message definitions you want to use in the event log.
Method Summary
  __init__(self, appname, dllname, logtype)
  close(self)
Clean up this handler.
  emit(self, record)
Emit a record.
  getEventCategory(self, record)
Return the event category for the record.
  getEventType(self, record)
Return the event type for the record.
  getMessageID(self, record)
Return the message ID for the event record.
    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.

Method Details

__init__(self, appname, dllname=None, logtype='Application')
(Constructor)

Overrides:
logging.Handler.__init__

close(self)

Clean up this handler.

You can remove the application name from the registry as a source of event log entries. However, if you do this, you will not be able to see the events as you intended in the Event Log Viewer - it needs to be able to access the registry to get the DLL name.
Overrides:
logging.Handler.close

emit(self, record)

Emit a record.

Determine the message ID, event category and event type. Then log the message in the NT event log.
Overrides:
logging.Handler.emit

getEventCategory(self, record)

Return the event category for the record.

Override this if you want to specify your own categories. This version returns 0.

getEventType(self, record)

Return the event type for the record.

Override this if you want to specify your own types. This version does a mapping using the handler's typemap attribute, which is set up in __init__() to a dictionary which contains mappings for DEBUG, INFO, WARNING, ERROR and CRITICAL. If you are using your own levels you will either need to override this method or place a suitable dictionary in the handler's typemap attribute.

getMessageID(self, record)

Return the message ID for the event record. If you are using your own messages, you could do this by having the msg passed to the logger being an ID rather than a formatting string. Then, in here, you could use a dictionary lookup to get the message ID. This version returns 1, which is the base message ID in win32service.pyd.