Skip to content

Commit

Permalink
Updated logging for the GUI and the EvaluationService to make sure er…
Browse files Browse the repository at this point in the history
…rors appear in the right location and that logs configured as '' are set to the right defaults.
  • Loading branch information
christophertubbs authored and aaraney committed Jan 23, 2024
1 parent 3fb2abc commit 94fee79
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
36 changes: 25 additions & 11 deletions python/gui/maas_experiment/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ def get_maas_logging_filename() -> str:
Returns:
Gets a suggested name for the core application log filename
"""
maas_log_filename = os.environ.get(
'APPLICATION_LOG_PATH',
os.path.join(application_values.BASE_DIRECTORY, f'{DEFAULT_LOGGER_NAME}.log')
)
maas_log_filename = os.environ.get('APPLICATION_LOG_PATH') \
or os.path.join(application_values.BASE_DIRECTORY, f'{DEFAULT_LOGGER_NAME}.log')

if not maas_log_filename.endswith(".log"):
maas_log_filename += ".log"
Expand All @@ -259,17 +257,33 @@ def get_socket_log_filename() -> str:
Returns:
The name of the log file for sockets
"""
socket_log_filename = os.environ.get(
"MAAS_SOCKET_LOG_PATH",
os.path.join(application_values.BASE_DIRECTORY, "MAASSockets.log")
)
socket_log_filename = os.environ.get("MAAS_SOCKET_LOG_PATH") \
or os.path.join(application_values.BASE_DIRECTORY, "MAASSockets.log")

if not socket_log_filename.endswith(".log"):
socket_log_filename += ".log"

return socket_log_filename


def get_error_log_filename() -> str:
"""
Gets the name of the log file for errors
Controlled via the optional `MAAS_ERROR_LOG_PATH` environment variable
Returns:
The name of the log file for errors
"""
error_log_filename = os.environ.get("MAAS_ERROR_LOG_PATH") \
or os.path.join(application_values.BASE_DIRECTORY, "errors.log")

if not error_log_filename.endswith(".log"):
error_log_filename += ".log"

return error_log_filename


def get_maximum_log_size() -> int:
"""
Determines the maximum allowable size of a log file in terms of bytes.
Expand Down Expand Up @@ -463,13 +477,13 @@ def create_handler_configuration(
possible_filename=get_socket_log_filename()
),
'stdout': {
'level': 'DEBUG',
'level': logging.DEBUG,
'class': 'logging.StreamHandler',
'formatter': 'standard_formatter'
},
"errors": {
"level": "ERROR",
"filename": "errors.log",
"level": logging.ERROR,
"filename": get_error_log_filename(),
"formatter": "standard_formatter",
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": get_maximum_log_size(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ def get_evaluation_service_logging_filename() -> str:
Returns:
Gets a suggested name for the core application log filename
"""
evaluation_service_log_filename = os.environ.get(
'APPLICATION_LOG_PATH',
os.path.join(application_values.BASE_DIRECTORY, f'{DEFAULT_LOGGER_NAME}.log')
)
evaluation_service_log_filename = os.environ.get('APPLICATION_LOG_PATH') \
or os.path.join(application_values.BASE_DIRECTORY, f'{DEFAULT_LOGGER_NAME}.log')

if not evaluation_service_log_filename.endswith(".log"):
evaluation_service_log_filename += ".log"
Expand All @@ -259,17 +257,33 @@ def get_socket_log_filename() -> str:
Returns:
The name of the log file for sockets
"""
socket_log_filename = os.environ.get(
"EVALUATION_SOCKET_LOG_PATH",
os.path.join(application_values.BASE_DIRECTORY, "EvaluationSockets.log")
)
socket_log_filename = os.environ.get("EVALUATION_SOCKET_LOG_PATH") \
or os.path.join(application_values.BASE_DIRECTORY, "EvaluationSockets.log")

if not socket_log_filename.endswith(".log"):
socket_log_filename += ".log"

return socket_log_filename


def get_error_log_filename() -> str:
"""
Gets the name of the log file for errors
Controlled via the optional `EVALUATION_ERROR_LOG_PATH` environment variable
Returns:
The name of the log file for errors
"""
error_log_filename = os.environ.get("EVALUATION_ERROR_LOG_PATH") \
or os.path.join(application_values.BASE_DIRECTORY, "errors.log")

if not error_log_filename.endswith(".log"):
error_log_filename += ".log"

return error_log_filename


def get_maximum_log_size() -> int:
"""
Determines the maximum allowable size of a log file in terms of bytes.
Expand Down Expand Up @@ -463,13 +477,13 @@ def create_handler_configuration(
possible_filename=get_socket_log_filename()
),
'stdout': {
'level': 'DEBUG',
'level': logging.DEBUG,
'class': 'logging.StreamHandler',
'formatter': 'standard_formatter'
},
"errors": {
"level": "ERROR",
"filename": "errors.log",
"level": logging.ERROR,
"filename": get_error_log_filename(),
"formatter": "standard_formatter",
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": get_maximum_log_size(),
Expand Down

0 comments on commit 94fee79

Please sign in to comment.