Skip to content

Commit

Permalink
General Settings GUI: Disable log level drop-down when logging is dis…
Browse files Browse the repository at this point in the history
…abled (nvaccess#10209)
  • Loading branch information
JulienCochuyt committed Sep 21, 2019
1 parent 0e4bb4a commit e83815c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
5 changes: 4 additions & 1 deletion source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ def makeSettings(self, settingsSizer):
logLevelChoices = [name for level, name in self.LOG_LEVELS]
self.logLevelList = settingsSizerHelper.addLabeledControl(logLevelLabelText, wx.Choice, choices=logLevelChoices)
curLevel = log.getEffectiveLevel()
if logHandler.isLogLevelForced():
self.logLevelList.Disable()
for index, (level, name) in enumerate(self.LOG_LEVELS):
if level == curLevel:
self.logLevelList.SetSelection(index)
Expand Down Expand Up @@ -792,7 +794,8 @@ def onSave(self):
config.conf["general"]["askToExit"]=self.askToExitCheckBox.IsChecked()
config.conf["general"]["playStartAndExitSounds"]=self.playStartAndExitSoundsCheckBox.IsChecked()
logLevel=self.LOG_LEVELS[self.logLevelList.GetSelection()][0]
config.conf["general"]["loggingLevel"]=logging.getLevelName(logLevel)
if not logHandler.isLogLevelForced:
config.conf["general"]["loggingLevel"] = logging.getLevelName(logLevel)
logHandler.setLogLevelFromConfig()
if self.startAfterLogonCheckBox.IsEnabled():
config.setStartAfterLogon(self.startAfterLogonCheckBox.GetValue())
Expand Down
22 changes: 19 additions & 3 deletions source/logHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ def initialize(shouldDoRemoteLogging=False):
except (IOError, WindowsError):
pass # Probably log does not exist, don't care.
logHandler = FileHandler(globalVars.appArgs.logFileName, mode="w",encoding="utf-8")
logLevel = globalVars.appArgs.logLevel
if globalVars.appArgs.debugLogging:
logLevel = Logger.DEBUG
elif logLevel <= 0:
logLevel = Logger.INFO
log.setLevel(logLevel)
else:
logHandler = RemoteHandler()
logFormatter = Formatter("%(codepath)s:\n%(message)s")
Expand All @@ -327,12 +333,22 @@ def initialize(shouldDoRemoteLogging=False):
warnings.showwarning = _showwarning
warnings.simplefilter("default", DeprecationWarning)


def isLogLevelForced() -> bool:
"""Check if the log level was overridden either from the command line or because of secure mode.
"""
return (
globalVars.appArgs.secure
or globalVars.appArgs.debugLogging
or globalVars.appArgs.logLevel != 0
or globalVars.appArgs.noLogging
)


def setLogLevelFromConfig():
"""Set the log level based on the current configuration.
"""
if globalVars.appArgs.debugLogging or globalVars.appArgs.logLevel != 0 or globalVars.appArgs.secure or globalVars.appArgs.noLogging:
# Log level was overridden on the command line or we're running in secure mode,
# so don't set it.
if isLogLevelForced:
return
import config
levelName=config.conf["general"]["loggingLevel"]
Expand Down
11 changes: 1 addition & 10 deletions source/nvda.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,8 @@ if isSecureDesktop:
# #8516: because config manager isn't ready yet, we must let start and exit messages be logged unless disabled via --no-logging switch.
# However, do log things if debug logging or log level other than 0 (not set) is requested from command line switches.

logLevel=globalVars.appArgs.logLevel
if globalVars.appArgs.noLogging and (not globalVars.appArgs.debugLogging and logLevel == 0):
logLevel = log.OFF
else:
if logLevel<=0:
logLevel=log.INFO
if globalVars.appArgs.debugLogging:
logLevel=log.DEBUG
logHandler.initialize()
logHandler.log.setLevel(logLevel)
if logLevel is log.DEBUG:
if logHandler.log.getEffectiveLevel() is log.DEBUG:
log.debug("Provided arguments: {}".format(sys.argv[1:]))
import buildVersion
log.info("Starting NVDA version %s" % buildVersion.version)
Expand Down

0 comments on commit e83815c

Please sign in to comment.