Skip to content

Commit

Permalink
Logging: Make log folder consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed Sep 11, 2024
1 parent 8bf93fa commit 9da07f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CreateStartupFilesController:
def __init__(self):
self.file_dir = os.path.dirname(os.path.realpath(__file__))
self.dp_directory = PurePath(self.file_dir, DataPackageServerConstants().DATAPACKAGEFOLDER)
self.logs_directory = PurePath(LoggingConstants().PARENTPATH)
self.logs_directory = PurePath(config.LogFilePath)
self.client_package = config.ClientPackages
self.createFolder()

Expand Down
27 changes: 10 additions & 17 deletions FreeTAKServer/core/configuration/LoggingConstants.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import os
from pathlib import PurePath, Path
from FreeTAKServer.core.configuration.MainConfig import MainConfig
config = MainConfig.instance()

class LoggingConstants:
def __init__(self, log_name = "FTS"):
#main logging config
# if on a unix type system with /var/log put the logs there
if os.path.isdir('/var/log') and os.access('/var/log', os.W_OK):
self.PARENTPATH = '/var'
self.LOGDIRECTORY = 'log'
else:
# determine the log path the old way under the execution path
self.CURRENTPATH = os.path.dirname(os.path.realpath(__file__))
self.CURRENTPATH = PurePath(self.CURRENTPATH)
self.PARENTPATH = str(self.CURRENTPATH.parents[0])
self.LOGDIRECTORY = 'logs'

# ensure directory exists
Path(PurePath(self.PARENTPATH, self.LOGDIRECTORY)).mkdir(parents=True, exist_ok=True)

# ensure directory exists
Path(PurePath(config.LogFilePath)).mkdir(parents=True, exist_ok=True)

self.LOGFORMAT = '%(levelname)s : %(asctime)s : %(filename)s:%(lineno)d : %(message)s'
self.LOGNAME = log_name

self.ERRORLOG = str(PurePath(self.PARENTPATH, f"{self.LOGDIRECTORY}/{self.LOGNAME}_error.log"))
self.DEBUGLOG = str(PurePath(self.PARENTPATH, f"{self.LOGDIRECTORY}/{self.LOGNAME}_debug.log"))
self.INFOLOG = str(PurePath(self.PARENTPATH, f"{self.LOGDIRECTORY}/{self.LOGNAME}_info.log"))
self.HTTPLOG = str(PurePath(self.PARENTPATH, f"{self.LOGDIRECTORY}/{self.LOGNAME}_http.log"))
self.ERRORLOG = str(PurePath(f"{config.LogFilePath}/{self.LOGNAME}_error.log"))
self.DEBUGLOG = str(PurePath(f"{config.LogFilePath}/{self.LOGNAME}_debug.log"))
self.INFOLOG = str(PurePath(f"{config.LogFilePath}/{self.LOGNAME}_info.log"))
self.HTTPLOG = str(PurePath(f"{config.LogFilePath}/{self.LOGNAME}_http.log"))
self.DELIMITER = ' ? '
self.MAXFILESIZE = 100000000
self.BACKUPCOUNT = 5
Expand Down

0 comments on commit 9da07f6

Please sign in to comment.