Skip to content

Commit

Permalink
SNH - Station Captain - Fix to permission issues logging when it does…
Browse files Browse the repository at this point in the history
…n't need it
  • Loading branch information
GregJohnStewart committed Aug 22, 2024
1 parent a143ca4 commit 1492b22
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions deployment/Single Host/Station-Captain/src/lib/LogUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,36 @@ class LogUtils:

@staticmethod
def setupLogging(logFile:str, console:bool=False):
Path(LogUtils.logDir).mkdir(parents=True, exist_ok=True)
LogUtils.logFile = logFile
filePresent:bool = False
if not os.path.exists(logFile):
try:
Path(LogUtils.logDir).mkdir(parents=True, exist_ok=True)
os.mknod(logFile)
LogUtils.logFile = logFile
filePresent = True
except Exception as e:
LogUtils.logFile = False
filePresent = False
else:
filePresent = True
logging.basicConfig(level=logging.NOTSET)

if console:
LogUtils.logLevel = logging.DEBUG

@staticmethod
def setupLogger(name: str) -> logging.Logger:
fh = logging.handlers.RotatingFileHandler(LogUtils.logDir+LogUtils.logFile, maxBytes=10*1024*1024, backupCount=5)
fh.setLevel(logging.DEBUG)

# sh = logging.StreamHandler()
# sh.setLevel(LogUtils.logLevel)

logOut = logging.getLogger(name)
# print(LogUtils.logLevel == logging.DEBUG)
logOut.setLevel(LogUtils.logLevel)
logOut.addHandler(fh)

if not LogUtils.logFile:
fh = logging.handlers.RotatingFileHandler(LogUtils.logDir+LogUtils.logFile, maxBytes=10*1024*1024, backupCount=5)
fh.setLevel(logging.DEBUG)
logOut.addHandler(fh)

# logOut.addHandler(sh)
return logOut

0 comments on commit 1492b22

Please sign in to comment.