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