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

_ClassType 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.

Instance Methods [hide private]
 
__init__(self, appname, dllname=None, logtype='Application')
Initializes the instance - basically setting the formatter to None and the filter list to empty.
 
getMessageID(self, record)
Return the message ID for the event record.
 
getEventCategory(self, record)
Return the event category for the record.
 
getEventType(self, record)
Return the event type for the record.
 
emit(self, record)
Emit a record.
 
close(self)
Clean up this handler.

Inherited from Handler: acquire, createLock, flush, format, handle, handleError, release, setFormatter, setLevel

Inherited from Filterer: addFilter, filter, removeFilter

Method Details [hide private]

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

 

Initializes the instance - basically setting the formatter to None and the filter list to empty.

Overrides: Filterer.__init__
(inherited documentation)

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.

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.

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

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: Handler.close