Repository: nvaccess/nvda

Issue:
When logging is disabled via command line, log level drop down should be greyed out
<!--
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/wiki/Github-issue-template-explanation-and-examples
-->

### Steps to reproduce:

Start NVDA either with the --no-logging, --secure or --log-level=100 command line switches

Open the General settings dialog (NVDA+control+g)
TAB to the Log Level drop-down
Modify the value

### Actual behavior:

The drop-down selection can be changed, although the logging level is not in fact changed when the apply or OK buttons are activated.

### Expected behavior:

The log level drop-down should be greyed out so the user cannot interact with it.  I've already had contact from one IT administrator trying to setup NVDA securely on their system, concerned that although they have disabled logging, this drop-down can be changed, which gives the appearance that the log level can be changed.

### System configuration
#### NVDA installed/portable/running from source:
Installed
#### NVDA version:
2019.2
#### Windows version:
Windows 10 Version: 
18362.1 
#### Name and version of other software in use when reproducing the issue:

#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your PC?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.



Discussion:
If someone wants to look at this, the change will need to be made in `source/gui/settingsDialogs.py`  in the `makeSettings` method of `GeneralSettingsPanel`. [Disable ](https://wxpython.org/Phoenix/docs/html/wx.Window.html#wx.Window.Disable) `self.logLevelList` when the log level is set from the command line. Probably best to extract the logic at the start of the `setLogLevelFromConfig` function in `source/logHandler.py`, put it in a new function in `source/logHandler.py` and use that.  It looks like there may be several other parts of the code base that rely on this same condition, it might be nice to centralise those while here. 

Resolving patch:
diff --git a/source/gui/settingsDialogs.py b/source/gui/settingsDialogs.py
--- a/source/gui/settingsDialogs.py
+++ b/source/gui/settingsDialogs.py
@@ -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)
@@ -792,8 +794,9 @@ 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)
-		logHandler.setLogLevelFromConfig()
+		if not logHandler.isLogLevelForced():
+			config.conf["general"]["loggingLevel"] = logging.getLevelName(logLevel)
+			logHandler.setLogLevelFromConfig()
 		if self.startAfterLogonCheckBox.IsEnabled():
 			config.setStartAfterLogon(self.startAfterLogonCheckBox.GetValue())
 		if self.startOnLogonScreenCheckBox.IsEnabled():
diff --git a/source/logHandler.py b/source/logHandler.py
--- a/source/logHandler.py
+++ b/source/logHandler.py
@@ -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")
@@ -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"]


Test patch: