Some minor improvements to the logging system

This commit is contained in:
Veronica K. B. Olsen
2021-01-25 17:11:05 +01:00
parent a420c1749a
commit 907a371bd4
4 changed files with 17 additions and 31 deletions
+16 -17
View File
@@ -157,13 +157,13 @@ def main(sysArgs=None):
) )
# Defaults # Defaults
debugLevel = logging.WARN logLevel = logging.WARN
logFormat = "{levelname:8} {message:}" logFormat = "{levelname:8} {message:}"
confPath = None confPath = None
dataPath = None dataPath = None
testMode = False testMode = False
qtStyle = "Fusion" qtStyle = "Fusion"
cmdOpen = None cmdOpen = None
# Parse Options # Parse Options
try: try:
@@ -186,12 +186,12 @@ def main(sysArgs=None):
) )
sys.exit(0) sys.exit(0)
elif inOpt == "--info": elif inOpt == "--info":
debugLevel = logging.INFO logLevel = logging.INFO
elif inOpt == "--debug": elif inOpt == "--debug":
debugLevel = logging.DEBUG logLevel = logging.DEBUG
logFormat = "[{asctime:}] {name:>22}:{lineno:<4d} {levelname:8} {message:}" logFormat = "[{asctime:}] {name:>22}:{lineno:<4d} {levelname:8} {message:}"
elif inOpt == "--verbose": elif inOpt == "--verbose":
debugLevel = VERBOSE logLevel = VERBOSE
logFormat = "[{asctime:}] {name:>22}:{lineno:<4d} {levelname:8} {message:}" logFormat = "[{asctime:}] {name:>22}:{lineno:<4d} {levelname:8} {message:}"
elif inOpt == "--style": elif inOpt == "--style":
qtStyle = inArg qtStyle = inArg
@@ -203,17 +203,16 @@ def main(sysArgs=None):
testMode = True testMode = True
# Set Config Options # Set Config Options
CONFIG.debugInfo = debugLevel < logging.INFO CONFIG.cmdOpen = cmdOpen
CONFIG.cmdOpen = cmdOpen
# Set Logging # Set Logging
logFmt = logging.Formatter(fmt=logFormat, style="{")
cHandle = logging.StreamHandler() cHandle = logging.StreamHandler()
cHandle.setLevel(debugLevel) cHandle.setFormatter(logging.Formatter(fmt=logFormat, style="{"))
cHandle.setFormatter(logFmt)
logger.addHandler(cHandle) pkgLogger = logging.getLogger(__package__)
pkgLogger.addHandler(cHandle)
pkgLogger.setLevel(logLevel)
logger.setLevel(debugLevel)
logger.info("Starting novelWriter %s (%s) %s" % ( logger.info("Starting novelWriter %s (%s) %s" % (
__version__, __hexversion__, __date__ __version__, __hexversion__, __date__
)) ))
-3
View File
@@ -55,9 +55,6 @@ class Config:
self.appName = "novelWriter" self.appName = "novelWriter"
self.appHandle = self.appName.lower() self.appHandle = self.appName.lower()
# Debug Settings
self.debugInfo = False # True if log level is DEBUG or VERBOSE
# Config Error Handling # Config Error Handling
self.hasError = False # True if the config class encountered an error self.hasError = False # True if the config class encountered an error
self.errData = [] # List of error messages self.errData = [] # List of error messages
+1 -6
View File
@@ -968,11 +968,6 @@ class GuiBuildNovel(QDialog):
""" """
buildCache = os.path.join(self.theProject.projCache, nwFiles.BUILD_CACHE) buildCache = os.path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
if self.mainConf.debugInfo:
nIndent = 2
else:
nIndent = None
logger.debug("Saving build cache") logger.debug("Saving build cache")
try: try:
with open(buildCache, mode="w+", encoding="utf8") as outFile: with open(buildCache, mode="w+", encoding="utf8") as outFile:
@@ -981,7 +976,7 @@ class GuiBuildNovel(QDialog):
"htmlStyle" : self.htmlStyle, "htmlStyle" : self.htmlStyle,
"nwdText" : self.nwdText, "nwdText" : self.nwdText,
"buildTime" : self.buildTime, "buildTime" : self.buildTime,
}, indent=nIndent)) }, indent=2))
except Exception as e: except Exception as e:
logger.error("Failed to save build cache") logger.error("Failed to save build cache")
logger.error(str(e)) logger.error(str(e))
-5
View File
@@ -78,7 +78,6 @@ def testBaseInit_Options(monkeypatch, tmpDir):
# Defaults w/None Args # Defaults w/None Args
nwGUI = nw.main() nwGUI = nw.main()
assert nw.logger.getEffectiveLevel() == logging.WARNING assert nw.logger.getEffectiveLevel() == logging.WARNING
assert nw.CONFIG.debugInfo is False
assert nwGUI.closeMain() == "closeMain" assert nwGUI.closeMain() == "closeMain"
# Defaults # Defaults
@@ -86,7 +85,6 @@ def testBaseInit_Options(monkeypatch, tmpDir):
["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir, "--style=Fusion"] ["--testmode", "--config=%s" % tmpDir, "--data=%s" % tmpDir, "--style=Fusion"]
) )
assert nw.logger.getEffectiveLevel() == logging.WARNING assert nw.logger.getEffectiveLevel() == logging.WARNING
assert nw.CONFIG.debugInfo is False
assert nwGUI.closeMain() == "closeMain" assert nwGUI.closeMain() == "closeMain"
# Log Levels # Log Levels
@@ -94,21 +92,18 @@ def testBaseInit_Options(monkeypatch, tmpDir):
["--testmode", "--info", "--config=%s" % tmpDir, "--data=%s" % tmpDir] ["--testmode", "--info", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
) )
assert nw.logger.getEffectiveLevel() == logging.INFO assert nw.logger.getEffectiveLevel() == logging.INFO
assert nw.CONFIG.debugInfo is False
assert nwGUI.closeMain() == "closeMain" assert nwGUI.closeMain() == "closeMain"
nwGUI = nw.main( nwGUI = nw.main(
["--testmode", "--debug", "--config=%s" % tmpDir, "--data=%s" % tmpDir] ["--testmode", "--debug", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
) )
assert nw.logger.getEffectiveLevel() == logging.DEBUG assert nw.logger.getEffectiveLevel() == logging.DEBUG
assert nw.CONFIG.debugInfo is True
assert nwGUI.closeMain() == "closeMain" assert nwGUI.closeMain() == "closeMain"
nwGUI = nw.main( nwGUI = nw.main(
["--testmode", "--verbose", "--config=%s" % tmpDir, "--data=%s" % tmpDir] ["--testmode", "--verbose", "--config=%s" % tmpDir, "--data=%s" % tmpDir]
) )
assert nw.logger.getEffectiveLevel() == 5 assert nw.logger.getEffectiveLevel() == 5
assert nw.CONFIG.debugInfo is True
assert nwGUI.closeMain() == "closeMain" assert nwGUI.closeMain() == "closeMain"
# Help and Version # Help and Version