@@ -1156,14 +1156,15 @@ def __init__(self, appname, dllname=None, logtype="Application"):
11561156 pass
11571157 self .deftype = _winapi .EVENTLOG_ERROR_TYPE
11581158 self .typemap = {
1159- logging .DEBUG : _winapi .EVENTLOG_INFORMATION_TYPE ,
1160- logging .INFO : _winapi .EVENTLOG_INFORMATION_TYPE ,
1161- logging .WARNING : _winapi .EVENTLOG_WARNING_TYPE ,
1162- logging .ERROR : _winapi .EVENTLOG_ERROR_TYPE ,
1159+ logging .DEBUG : _winapi .EVENTLOG_INFORMATION_TYPE ,
1160+ logging .INFO : _winapi .EVENTLOG_INFORMATION_TYPE ,
1161+ logging .WARNING : _winapi .EVENTLOG_WARNING_TYPE ,
1162+ logging .ERROR : _winapi .EVENTLOG_ERROR_TYPE ,
11631163 logging .CRITICAL : _winapi .EVENTLOG_ERROR_TYPE ,
11641164 }
11651165
1166- def _add_source_to_registry (self , appname , dllname , logtype ):
1166+ @staticmethod
1167+ def _add_source_to_registry (appname , dllname , logtype ):
11671168 import winreg
11681169
11691170 key_path = f"SYSTEM\\ CurrentControlSet\\ Services\\ EventLog\\ { logtype } \\ { appname } "
@@ -1212,22 +1213,21 @@ def emit(self, record):
12121213 Determine the message ID, event category and event type. Then
12131214 log the message in the NT event log.
12141215 """
1215- if self ._winapi :
1216- try :
1217- id = self .getMessageID (record )
1218- cat = self .getEventCategory (record )
1219- type = self .getEventType (record )
1220- msg = self .format (record )
1221-
1222- # Get a handle to the event log
1223- handle = self ._winapi .RegisterEventSource (None , self .appname )
1224- if handle != self ._winapi .INVALID_HANDLE_VALUE :
1225- try :
1226- self ._winapi .ReportEvent (handle , type , cat , id , [msg ])
1227- finally :
1228- self ._winapi .DeregisterEventSource (handle )
1229- except Exception :
1230- self .handleError (record )
1216+ try :
1217+ id = self .getMessageID (record )
1218+ cat = self .getEventCategory (record )
1219+ type = self .getEventType (record )
1220+ msg = self .format (record )
1221+
1222+ # Get a handle to the event log
1223+ handle = self ._winapi .RegisterEventSource (None , self .appname )
1224+ if handle != self ._winapi .INVALID_HANDLE_VALUE :
1225+ try :
1226+ self ._winapi .ReportEvent (handle , type , cat , id , [msg ])
1227+ finally :
1228+ self ._winapi .DeregisterEventSource (handle )
1229+ except Exception :
1230+ self .handleError (record )
12311231
12321232 def close (self ):
12331233 """
0 commit comments