summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2022-08-27 11:13:19 (GMT)
committerGitHub <noreply@github.com>2022-08-27 11:13:19 (GMT)
commit013e659e495796df77aae4d33b67995f9793f454 (patch)
tree169340e4c12a5003e4ba6b3a128b524d30874304 /Lib/logging
parent0ace820bec8892d621a4aadc1feb6c56e25560bf (diff)
downloadcpython-013e659e495796df77aae4d33b67995f9793f454.zip
cpython-013e659e495796df77aae4d33b67995f9793f454.tar.gz
cpython-013e659e495796df77aae4d33b67995f9793f454.tar.bz2
gh-92007: Handle elevation errors in NTEventLogHandler more graceā€¦ (GH-96322)
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 3f97862..b4c5c13 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1111,7 +1111,16 @@ class NTEventLogHandler(logging.Handler):
dllname = os.path.join(dllname[0], r'win32service.pyd')
self.dllname = dllname
self.logtype = logtype
- self._welu.AddSourceToRegistry(appname, dllname, logtype)
+ # Administrative privileges are required to add a source to the registry.
+ # This may not be available for a user that just wants to add to an
+ # existing source - handle this specific case.
+ try:
+ self._welu.AddSourceToRegistry(appname, dllname, logtype)
+ except Exception as e:
+ # This will probably be a pywintypes.error. Only raise if it's not
+ # an "access denied" error, else let it pass
+ if getattr(e, 'winerror', None) != 5: # not access denied
+ raise
self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE
self.typemap = {
logging.DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,