Skip to content

Commit

Permalink
Merge pull request #737 from stephendade/logging-fix
Browse files Browse the repository at this point in the history
Logging fixes
  • Loading branch information
brothercorvo authored Sep 29, 2024
2 parents 2b7915f + 94c6e99 commit d04cbba
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_domain]
level=DEBUG
level=ERROR
qualname=domain
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
6 changes: 3 additions & 3 deletions FreeTAKServer/components/core/type/configuration/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_type]
level=DEBUG
level=ERROR
qualname=type
handlers=fileHandler

Expand All @@ -25,7 +25,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_xml_serializer]
level=DEBUG
level=ERROR
qualname=xml_serializer
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_emergency]
level=DEBUG
level=ERROR
qualname=emergency
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_excheck]
level=DEBUG
level=ERROR
qualname=excheck
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_mission]
level=DEBUG
level=ERROR
qualname=mission
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
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
3 changes: 2 additions & 1 deletion FreeTAKServer/core/configuration/MainConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ def validate_and_sanitize_path(self, path):
sanitized_path = ROOTPATH + os.path.relpath(os.path.normpath(os.path.join(os.sep, path)), os.sep)

if not os.access(sanitized_path, os.F_OK) or not os.access(sanitized_path, os.W_OK):
raise ValueError
print(f"Cannot access configuration path: {sanitized_path}")
sys.exit(1)

return sanitized_path

Expand Down
14 changes: 7 additions & 7 deletions FreeTAKServer/core/configuration/configuration_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ def ask_user_for_config():
else:
print('invalid database type')
config.DBFilePath = database_path
add_to_config(data=database_path, path=["FileSystem", "FTS_DB_PATH"], source=yaml_config)
add_to_config(data=database_path, path=["Filesystem", "FTS_DB_PATH"], source=yaml_config)

main_path = get_user_input(question="enter the preferred main path", default=config.MainPath)
while not valid_and_safe_path(main_path):
print("Invalid path. Path does not exist or insufficient permissions exist.")
main_path = get_user_input(question="enter the preferred main path", default=config.MainPath)

config.MainPath = main_path
add_to_config(path=["FileSystem", "FTS_MAINPATH"], data= main_path, source= yaml_config)
add_to_config(path=["Filesystem", "FTS_MAINPATH"], data= main_path, source= yaml_config)

log_path = get_user_input(question="enter the preferred log file path", default=config.LogFilePath)
while not valid_and_safe_path(log_path):
print("Invalid path. Path does not exist or insufficient permissions exist.")
log_path = get_user_input(question="enter the preferred log file path", default=config.LogFilePath)

add_to_config(path=["FileSystem", "FTS_LOGFILE_PATH"], data=log_path, source=yaml_config)
add_to_config(path=["Filesystem", "FTS_LOGFILE_PATH"], data=log_path, source=yaml_config)

add_to_config(path=["System", "FTS_NODE_ID"], data=config.nodeID, source=yaml_config)

Expand Down Expand Up @@ -156,9 +156,9 @@ def autogenerate_config():

add_to_config(data=config.UserConnectionIP, path=["Addresses", "FTS_DP_ADDRESS"], source=yaml_config)
add_to_config(data=config.UserConnectionIP, path=["Addresses", "FTS_USER_ADDRESS"], source=yaml_config)
add_to_config(data=config.DBFilePath, path=["FileSystem", "FTS_DB_PATH"], source=yaml_config)
add_to_config(path=["FileSystem", "FTS_MAINPATH"], data=config.MainPath, source=yaml_config)
add_to_config(path=["FileSystem", "FTS_LOGFILE_PATH"], data=config.LogFilePath, source=yaml_config)
add_to_config(data=config.DBFilePath, path=["Filesystem", "FTS_DB_PATH"], source=yaml_config)
add_to_config(path=["Filesystem", "FTS_MAINPATH"], data=config.MainPath, source=yaml_config)
add_to_config(path=["Filesystem", "FTS_LOGFILE_PATH"], data=config.LogFilePath, source=yaml_config)
add_to_config(path=["System", "FTS_NODE_ID"], data=config.nodeID, source=yaml_config)

file = open(config.yaml_path, mode="w+")
Expand All @@ -185,7 +185,7 @@ def autogenerate_config():
#FTS_API_PORT: 19023
#FTS_FED_PORT: 9000
#FTS_API_ADDRESS: 0.0.0.0
FileSystem:
Filesystem:
FTS_DB_PATH: /opt/fts/FreeTAKServer.db
#FTS_COT_TO_DB: True
FTS_PERSISTENCE_PATH: /opt/fts/
Expand Down
6 changes: 3 additions & 3 deletions FreeTAKServer/core/cot_management/configuration/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_cotmanagement]
level=DEBUG
level=ERROR
qualname=cotmanagement
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down
6 changes: 3 additions & 3 deletions FreeTAKServer/core/enterprise_sync/configuration/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ keys=stream_handler,fileHandler
keys=formatter

[logger_root]
level=DEBUG
level=ERROR
handlers=fileHandler

[logger_enterprisesync]
level=DEBUG
level=ERROR
qualname=enterprisesync
handlers=fileHandler

Expand All @@ -24,7 +24,7 @@ args=(sys.stderr,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
level=ERROR
formatter=formatter
args=('%(logfilename)s',)

Expand Down

0 comments on commit d04cbba

Please sign in to comment.