Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable logging for python dependencies, particularly comtypes #10393

Merged
merged 5 commits into from Oct 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions source/logHandler.py
Expand Up @@ -17,6 +17,7 @@
from types import MethodType, FunctionType
import globalVars
import buildVersion
from typing import Optional

ERROR_INVALID_WINDOW_HANDLE = 1400
ERROR_TIMEOUT = 1460
Expand Down Expand Up @@ -267,8 +268,9 @@ def redirectStdout(logger):
# Register our logging class as the class for all loggers.
logging.setLoggerClass(Logger)
#: The singleton logger instance.
#: @type: L{Logger}
log = logging.getLogger("nvda")
log: Logger = logging.getLogger("nvda")
#: The singleton log handler instance.
logHandler: Optional[logging.Handler] = None

def _getDefaultLogFilePath():
if getattr(sys, "frozen", None):
Expand All @@ -290,7 +292,7 @@ def initialize(shouldDoRemoteLogging=False):
@var shouldDoRemoteLogging: True if all logging should go to the real NVDA via rpc (for slave)
@type shouldDoRemoteLogging: bool
"""
global log
global log, logHandler
logging.addLevelName(Logger.DEBUGWARNING, "DEBUGWARNING")
logging.addLevelName(Logger.IO, "IO")
logging.addLevelName(Logger.OFF, "OFF")
Expand All @@ -307,7 +309,7 @@ def initialize(shouldDoRemoteLogging=False):
# #8516: also if logging is completely turned off.
logHandler = logging.NullHandler()
# There's no point in logging anything at all, since it'll go nowhere.
log.setLevel(Logger.OFF)
log.root.setLevel(Logger.OFF)
else:
if not globalVars.appArgs.logFileName:
globalVars.appArgs.logFileName = _getDefaultLogFilePath()
Expand All @@ -327,14 +329,15 @@ def initialize(shouldDoRemoteLogging=False):
elif logLevel <= 0:
logLevel = Logger.INFO
log.setLevel(logLevel)
log.root.setLevel(max(logLevel, logging.WARN))
else:
logHandler = RemoteHandler()
logFormatter = Formatter(
fmt="{codepath!s}:\n{message}",
style="{"
)
logHandler.setFormatter(logFormatter)
log.addHandler(logHandler)
log.root.addHandler(logHandler)
redirectStdout(log)
sys.excepthook = _excepthook
warnings.showwarning = _showwarning
Expand Down Expand Up @@ -368,3 +371,4 @@ def setLogLevelFromConfig():
level = log.INFO
config.conf["general"]["loggingLevel"] = logging.getLevelName(log.INFO)
log.setLevel(level)
log.root.setLevel(max(level, logging.WARN))