Skip to content

Enable logging for python dependencies, particularly comtypes#10393

Merged
michaelDCurran merged 5 commits into
nvaccess:masterfrom
BabbageCom:comtypesLogging
Oct 21, 2019
Merged

Enable logging for python dependencies, particularly comtypes#10393
michaelDCurran merged 5 commits into
nvaccess:masterfrom
BabbageCom:comtypesLogging

Conversation

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Link to issue number:

Related to #10247
Comtypes issue enthought/comtypes#192

Summary of the issue:

Some of our dependencies, particularly comtypes, have built in logging. However, logging data from these dependencies is ignored, as the NVDA logfile handler is set on the NVDA logger, not on the root logger of all loggers.

Description of how this pull request fixes the issue:

This pr registers our logHandler to the root logger. This means that python modules that use python's logging facility (not the NVDA specific one) are still able to log their information to the NVDA log.

The NVDA log level is also applied to the root logger, but only if it is warning or higher. This is because warnings or errors logged by dependencies like comtypes are certainly very interesting to know, though we want to avoid comtypes debug information leaking into our log when our log level is debug.

Testing performed:

Tested that comtypes.logger.error logs its data to the NVDA log and plays the NVDA error sound.

Known issues with pull request:

I initially started with a comtypes specific implementation that registered our log handler to the comtypes logger and was also able to log comtypes output at level debug. However, having comtypes log at the debug level is very verbose and, more importantly, can cause serious issues as some of its logging is re-entrant. Long story short, comtypes debug logging is not what we want.

Here is an example traceback generated when comtypes logging is set to debug. Strange enough, even though that traceback was sent to stderr, it didn't pop up in the log. I had to manually monkeypatch stderr to a text file in order for the traceback to be retrieved.

Change log entry:

  • Changes
    • Third party python packages included in NVDA, such as comtypes, now log their warnings and errors to the NVDA log.

@Brian1Gaff

This comment has been minimized.

@Brian1Gaff

This comment has been minimized.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

This is not in alpha yet.

@Brian1Gaff

Brian1Gaff commented Oct 17, 2019 via email

Copy link
Copy Markdown

@michaelDCurran michaelDCurran merged commit 60f068e into nvaccess:master Oct 21, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Oct 21, 2019
michaelDCurran added a commit that referenced this pull request Oct 21, 2019
@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

This already proves to be helpful. When I open the Emoji panel in Windows 20:1 insider preview, i"m getting unhandled exceptions by our UIA event handler. I was already investing some resources in increasing UIA logging, so I fixed this in #10397 hopefully.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

Here is an example traceback:

ERROR - comtypes._comobject.call_without_this (08:41:05.355) - Dummy-5 (5384):
Exception in IUIAutomationFocusChangedEventHandler.HandleFocusChangedEvent implementation:
Traceback (most recent call last):
  File "comtypes\_comobject.pyc", line 147, in call_without_this
  File "_UIAHandler.pyc", line 328, in IUIAutomationFocusChangedEventHandler_HandleFocusChangedEvent
  File "comtypes\__init__.pyc", line 279, in __getattr__
  File "comtypesMonkeyPatches.pyc", line 26, in __call__
_ctypes.COMError: (-2147220991, 'Een gebeurtenis kan geen van de abonnees aanroepen', (None, None, None, 0, None))

In my opinion, we should catch these in NVDA

@LeonarddeR LeonarddeR deleted the comtypesLogging branch November 21, 2019 09:10
JulienCochuyt added a commit to accessolutions/nvda that referenced this pull request May 11, 2020
SaschaCowley pushed a commit that referenced this pull request May 13, 2025
Follow up for #10393

Summary of the issue:
Since #10393, we log at level warning or higher for external Python
dependencies. There is no way to enable logging at lower levels, such as
debug. This can however be pretty helpful for external dependencies like
comtypes to see what's going on under the hood.

Description of user facing changes
Have extra logging when a new debugging category,
`externalPythonDependencies`, is enabled.

Description of development approach
The overall logging level is now determined from the level of the root
logger, which is no longer limited to a minimum of WARNING. Instead, a
filter is implemented on the handler that filters appropriately. Note
that initially, it made sense to add this filter to the root logger, but
filters don't propagate from the root logger to all loggers below.

Testing strategy:
Calling `comtypes.CoInitialize` with and without the new category
enabled, logging at level debug. Ensured that behavior was as expected
(i.e. comtypes logged when the category was enabled)

Known issues with pull request:
In #10393, I mentioned issues with re-entrancy when comtypes logs at
level debug. I have not yet reproduced this. That said, the logging
categories are documented in such a way that they should only be enabled
on request. I don't think this needs extra documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants