Back to index

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

List of all members.

Public Member Functions

def __init__
def getMessageID
def getEventCategory
def getEventType
def emit
def close

Public Attributes

 appname
 dllname
 logtype
 deftype
 typemap

Private Attributes

 _welu

Detailed Description

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.

Definition at line 886 of file handlers.py.


Constructor & Destructor Documentation

def logging.handlers.NTEventLogHandler.__init__ (   self,
  appname,
  dllname = None,
  logtype = "Application" 
)

Definition at line 896 of file handlers.py.

00896 
00897     def __init__(self, appname, dllname=None, logtype="Application"):
00898         logging.Handler.__init__(self)
00899         try:
00900             import win32evtlogutil, win32evtlog
00901             self.appname = appname
00902             self._welu = win32evtlogutil
00903             if not dllname:
00904                 dllname = os.path.split(self._welu.__file__)
00905                 dllname = os.path.split(dllname[0])
00906                 dllname = os.path.join(dllname[0], r'win32service.pyd')
00907             self.dllname = dllname
00908             self.logtype = logtype
00909             self._welu.AddSourceToRegistry(appname, dllname, logtype)
00910             self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
00911             self.typemap = {
00912                 logging.DEBUG   : win32evtlog.EVENTLOG_INFORMATION_TYPE,
00913                 logging.INFO    : win32evtlog.EVENTLOG_INFORMATION_TYPE,
00914                 logging.WARNING : win32evtlog.EVENTLOG_WARNING_TYPE,
00915                 logging.ERROR   : win32evtlog.EVENTLOG_ERROR_TYPE,
00916                 logging.CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,
00917          }
00918         except ImportError:
00919             print("The Python Win32 extensions for NT (service, event "\
00920                         "logging) appear not to be available.")
00921             self._welu = None

Here is the caller graph for this function:


Member Function Documentation

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.

Definition at line 973 of file handlers.py.

00973 
00974     def close(self):
00975         """
00976         Clean up this handler.
00977 
00978         You can remove the application name from the registry as a
00979         source of event log entries. However, if you do this, you will
00980         not be able to see the events as you intended in the Event Log
00981         Viewer - it needs to be able to access the registry to get the
00982         DLL name.
00983         """
00984         #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)
00985         logging.Handler.close(self)

Here is the caller graph for this function:

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

Determine the message ID, event category and event type. Then
log the message in the NT event log.

Definition at line 954 of file handlers.py.

00954 
00955     def emit(self, record):
00956         """
00957         Emit a record.
00958 
00959         Determine the message ID, event category and event type. Then
00960         log the message in the NT event log.
00961         """
00962         if self._welu:
00963             try:
00964                 id = self.getMessageID(record)
00965                 cat = self.getEventCategory(record)
00966                 type = self.getEventType(record)
00967                 msg = self.format(record)
00968                 self._welu.ReportEvent(self.appname, id, cat, type, [msg])
00969             except (KeyboardInterrupt, SystemExit):
00970                 raise
00971             except:
00972                 self.handleError(record)

Here is the call graph for this function:

Return the event category for the record.

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

Definition at line 932 of file handlers.py.

00932 
00933     def getEventCategory(self, record):
00934         """
00935         Return the event category for the record.
00936 
00937         Override this if you want to specify your own categories. This version
00938         returns 0.
00939         """
00940         return 0

Here is the caller graph for this function:

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.

Definition at line 941 of file handlers.py.

00941 
00942     def getEventType(self, record):
00943         """
00944         Return the event type for the record.
00945 
00946         Override this if you want to specify your own types. This version does
00947         a mapping using the handler's typemap attribute, which is set up in
00948         __init__() to a dictionary which contains mappings for DEBUG, INFO,
00949         WARNING, ERROR and CRITICAL. If you are using your own levels you will
00950         either need to override this method or place a suitable dictionary in
00951         the handler's typemap attribute.
00952         """
00953         return self.typemap.get(record.levelno, self.deftype)

Here is the caller graph for this function:

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.

Definition at line 922 of file handlers.py.

00922 
00923     def getMessageID(self, record):
00924         """
00925         Return the message ID for the event record. If you are using your
00926         own messages, you could do this by having the msg passed to the
00927         logger being an ID rather than a formatting string. Then, in here,
00928         you could use a dictionary lookup to get the message ID. This
00929         version returns 1, which is the base message ID in win32service.pyd.
00930         """
00931         return 1

Here is the caller graph for this function:


Member Data Documentation

Definition at line 901 of file handlers.py.

Definition at line 900 of file handlers.py.

Definition at line 909 of file handlers.py.

Definition at line 906 of file handlers.py.

Definition at line 907 of file handlers.py.

Definition at line 910 of file handlers.py.


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