Skip to content

Commit

Permalink
SNH - Station Captain - Fixed bug keeping oqm-config from working whe…
Browse files Browse the repository at this point in the history
…re it can without root
  • Loading branch information
GregJohnStewart committed Jan 12, 2025
1 parent 3f6d07a commit b860f02
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions deployment/Single Host/Station-Captain/src/lib/LogUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ class LogUtils:
https://docs.python.org/3/library/logging.html
"""
defaultFormat = '%(levelname)-8s :: %(name)-13s :: %(message)s'
defaultFormat = '%(levelname)-8s :: %(name)-13s :: %(message)s'
defaultFormatWithTime = '%(asctime)s :: %(levelname)-8s :: %(name)-13s :: %(message)s'
fileLogLevel = logging.DEBUG
consoleLogLevel = logging.DEBUG
logDir = "/var/log/oqm/"
logFile = ""
fileHandler = None
consoleHandler = None
logFileMaxSize = 50*1024*1024 # 50 MB
logFileMaxSize = 50 * 1024 * 1024 # 50 MB
logFileBackups = 5

@staticmethod
def setupLogging(logFile:str, console:bool=False):
def setupLogging(logFile: str, console: bool = False):
"""
Only to be run at beginning of script (main), before any modules call setupLogger. Only call once.
:param logFile: The file within LogUtils.logDir to use for this run
Expand All @@ -39,7 +39,7 @@ def setupLogging(logFile:str, console:bool=False):
"""
logFile = LogUtils.logDir + logFile
LogUtils.logFile = logFile
filePresent:bool = False
filePresent: bool = False
if not os.path.exists(logFile):
try:
Path(LogUtils.logDir).mkdir(parents=True, exist_ok=True)
Expand All @@ -57,10 +57,14 @@ def setupLogging(logFile:str, console:bool=False):
LogUtils.consoleHandler = fh

if filePresent:
fh = logging.handlers.RotatingFileHandler(LogUtils.logFile, mode="a", maxBytes=LogUtils.logFileMaxSize, backupCount=LogUtils.logFileBackups)
fh.setFormatter(logging.Formatter(LogUtils.defaultFormatWithTime))
fh.setLevel(LogUtils.fileLogLevel)
LogUtils.fileHandler = fh
try:
fh = logging.handlers.RotatingFileHandler(LogUtils.logFile, mode="a", maxBytes=LogUtils.logFileMaxSize,
backupCount=LogUtils.logFileBackups)
fh.setFormatter(logging.Formatter(LogUtils.defaultFormatWithTime))
fh.setLevel(LogUtils.fileLogLevel)
LogUtils.fileHandler = fh
except Exception as e:
fh = None

@staticmethod
def setupLogger(name: str) -> logging.Logger:
Expand Down

0 comments on commit b860f02

Please sign in to comment.