From 9c654357c82b7a67f0da71e23c3558fe7159e75c Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Thu, 26 Sep 2024 11:10:51 +0200 Subject: [PATCH 1/8] ISEPOS-2280 Added base loggers scripts --- matlab/logging/base_logger.m | 111 ++++++++++++++++++++++++++++++++++++++++++ octave/logging/base_logger.m | 111 ++++++++++++++++++++++++++++++++++++++++++ python/logging/base_logger.py | 55 +++++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 matlab/logging/base_logger.m create mode 100644 octave/logging/base_logger.m create mode 100644 python/logging/base_logger.py diff --git a/matlab/logging/base_logger.m b/matlab/logging/base_logger.m new file mode 100644 index 0000000..75b6e58 --- /dev/null +++ b/matlab/logging/base_logger.m @@ -0,0 +1,111 @@ +% +% ----------------- +% Copyright © 2024 ACK Cyfronet AGH, Poland. +% ----------------- +% +% BASE_LOGGER A singleton logger class for logging messages to a file. +% +% This class implements a simple logging mechanism with different log levels +% (TRACE, DEBUG, INFO, WARNING, ERROR) and writes log entries to a file. +% It follows the Singleton pattern to ensure that only one instance of the logger +% exists throughout the application. +% +% Properties: +% fid - (private) The file identifier for the log file. This is used to write logs. +% +% Methods: +% +% getInstance() - Retrieves the singleton instance of the logger. +% +% trace(message) - Logs a message with TRACE level. +% @param message The message to log. +% +% debug(message) - Logs a message with DEBUG level. +% @param message The message to log. +% +% info(message) - Logs a message with INFO level. +% @param message The message to log. +% +% warning(message) - Logs a message with WARNING level. +% @param message The message to log. +% +% error(message) - Logs a message with ERROR level. +% @param message The message to log. +% +% delete() - Destructor method that closes the file identifier when the logger is deleted. +% +% Example usage: +% logger = base_logger.getInstance(); +% logger.info('This is an info message'); +% logger.error('This is an error message'); +% +% See also: fopen, fclose, dbstack, fprintf + +classdef base_logger < handle + properties(Access=private) + fid; + end + + methods(Static, Access = public) + function obj = getInstance() + persistent instance; + if isempty(instance) + instance = base_logger(); + end + obj = instance; + end + end + + methods(Access=private) + function this = base_logger() + this.fid = fopen(getenv("DEFAULT_LOG_PATH"), 'a'); + if this.fid == -1 + error('Failed to open log file: application.log'); + end + end + + function log(this, level, message) + current_time = datetime('now', 'Format', 'yyyy-MM-dd HH:mm:ss'); + stack = dbstack('-completenames'); + if length(stack) > 2 + script_name = stack(3).name; + else + script_name = 'Unknown'; + end + + if this.fid ~= -1 + fprintf(this.fid, '%s %s %s %s\n', char(current_time), level, script_name, message); + else + error('File identifier is invalid. Cannot write to log.'); + end + end + end + + methods(Access=public) + function trace(this, message) + this.log("TRACE", message); + end + + function debug(this, message) + this.log("DEBUG", message); + end + + function info(this, message) + this.log("INFO", message); + end + + function warning(this, message) + this.log("WARNING", message); + end + + function error(this, message) + this.log("ERROR", message); + end + + function delete(this) + if this.fid ~= -1 + fclose(this.fid); + end + end + end +end \ No newline at end of file diff --git a/octave/logging/base_logger.m b/octave/logging/base_logger.m new file mode 100644 index 0000000..101ee18 --- /dev/null +++ b/octave/logging/base_logger.m @@ -0,0 +1,111 @@ +% +% ----------------- +% Copyright © 2024 ACK Cyfronet AGH, Poland. +% ----------------- +% +% BASE_LOGGER A singleton logger class for logging messages to a file. +% +% This class implements a simple logging mechanism with different log levels +% (TRACE, DEBUG, INFO, WARNING, ERROR) and writes log entries to a file. +% It follows the Singleton pattern to ensure that only one instance of the logger +% exists throughout the application. +% +% Properties: +% fid - (private) The file identifier for the log file. This is used to write logs. +% +% Methods: +% +% getInstance() - Retrieves the singleton instance of the logger. +% +% trace(message) - Logs a message with TRACE level. +% @param message The message to log. +% +% debug(message) - Logs a message with DEBUG level. +% @param message The message to log. +% +% info(message) - Logs a message with INFO level. +% @param message The message to log. +% +% warning(message) - Logs a message with WARNING level. +% @param message The message to log. +% +% error(message) - Logs a message with ERROR level. +% @param message The message to log. +% +% delete() - Destructor method that closes the file identifier when the logger is deleted. +% +% Example usage: +% logger = base_logger.getInstance(); +% logger.info('This is an info message'); +% logger.error('This is an error message'); +% +% See also: fopen, fclose, dbstack, fprintf + +classdef base_logger < handle + properties(Access=private) + fid; + end + + methods(Static, Access = public) + function obj = getInstance() + persistent instance; + if isempty(instance) + instance = base_logger(); + end + obj = instance; + end + end + + methods(Access=private) + function this = base_logger() + this.fid = fopen(getenv("DEFAULT_LOG_PATH"), 'a'); + if this.fid == -1 + error('Failed to open log file: application.log'); + end + end + + function log(this, level, message) + current_time = strftime('%Y-%m-%d %H:%M:%S', localtime(time())); + stack = dbstack('-completenames'); + if length(stack) > 2 + script_name = stack(3).name; + else + script_name = 'Unknown'; + end + + if this.fid ~= -1 + fprintf(this.fid, '%s %s %s %s\n', char(current_time), level, script_name, message); + else + error('File identifier is invalid. Cannot write to log.'); + end + end + end + + methods(Access=public) + function trace(this, message) + this.log("TRACE", message); + end + + function debug(this, message) + this.log("DEBUG", message); + end + + function info(this, message) + this.log("INFO", message); + end + + function warning(this, message) + this.log("WARNING", message); + end + + function error(this, message) + this.log("ERROR", message); + end + + function delete(this) + if this.fid ~= -1 + fclose(this.fid); + end + end + end +end \ No newline at end of file diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py new file mode 100644 index 0000000..e4af80b --- /dev/null +++ b/python/logging/base_logger.py @@ -0,0 +1,55 @@ +# +# ----------------- +# Copyright © 2024 ACK Cyfronet AGH, Poland. +# ----------------- +# +import os +import logging + +def getDefaultLogger(name): + """ + Retrieves or creates a logger with the specified name and sets it up with a file handler. + + The logger is configured to write log messages to the file path specified by the + 'DEFAULT_LOG_PATH' environment variable. It uses the 'INFO' level as the default + logging level and writes log entries in the following format: + + 'YYYY-MM-DD HH:MM:SS,ms LEVEL logger_name message' + + If the logger does not already have handlers, a file handler is created, and the + logging output is appended to the file. The log format includes the timestamp with + milliseconds, log level, logger name, and the log message. + + Parameters: + ----------- + name : str + The name of the logger. This can be the name of the module or any identifier + that you want to associate with the logger. + + Returns: + -------- + logger : logging.Logger + A logger instance with the specified name. The logger is configured with a + file handler that writes to the file specified by the 'DEFAULT_LOG_PATH' + environment variable. + + Raises: + ------- + KeyError: + If the 'DEFAULT_LOG_PATH' environment variable is not set. + + Example: + -------- + logger = getDefaultLogger(__name__) + logger.info("This is an info message.") + + """ + logger = logging.getLogger(name) + if not logger.hasHandlers(): + file_handler = logging.FileHandler(os.environ['DEFAULT_LOG_PATH'], mode='a') + formatter = logging.Formatter('%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s') + file_handler.setFormatter(formatter) + logger.addHandler(file_handler) + logger.setLevel(logging.INFO) + + return logger \ No newline at end of file From 039cfe081e3a5f4d7266cc4dd9e178679cbe347e Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 30 Sep 2024 23:46:26 +0200 Subject: [PATCH 2/8] ISEPOS-2280 Enchanced and adjusted base loggers --- matlab/logging/base_logger.m | 64 ++++++++++++++++++++++++------------- octave/logging/base_logger.m | 73 +++++++++++++++++++++++++++---------------- python/logging/base_logger.py | 2 +- 3 files changed, 89 insertions(+), 50 deletions(-) diff --git a/matlab/logging/base_logger.m b/matlab/logging/base_logger.m index 75b6e58..1468182 100644 --- a/matlab/logging/base_logger.m +++ b/matlab/logging/base_logger.m @@ -34,10 +34,15 @@ % % delete() - Destructor method that closes the file identifier when the logger is deleted. % -% Example usage: +% Example Usage: % logger = base_logger.getInstance(); -% logger.info('This is an info message'); -% logger.error('This is an error message'); +% logger.info('Some info') +% +% try +% error('Simulated error for stack trace logging'); +% catch err +% logger.error('An error occurred:', err); +% end % % See also: fopen, fclose, dbstack, fprintf @@ -58,48 +63,63 @@ classdef base_logger < handle methods(Access=private) function this = base_logger() - this.fid = fopen(getenv("DEFAULT_LOG_PATH"), 'a'); + this.fid = fopen(getenv("APP_LOG_FILE"), 'a'); if this.fid == -1 - error('Failed to open log file: application.log'); + error('Failed to open log file'); end end - function log(this, level, message) - current_time = datetime('now', 'Format', 'yyyy-MM-dd HH:mm:ss'); + function log(this, level, varargin) + current_time = datestr(now, 'yyyy-mm-dd HH:MM:SS'); stack = dbstack('-completenames'); if length(stack) > 2 script_name = stack(3).name; else script_name = 'Unknown'; end - - if this.fid ~= -1 - fprintf(this.fid, '%s %s %s %s\n', char(current_time), level, script_name, message); - else - error('File identifier is invalid. Cannot write to log.'); + + message = ""; + for i = 1:numel(varargin) + if isa(varargin{i}, 'MException') + message = sprintf('%sError: %s\n', message, varargin{i}.message); + for j = 1:length(varargin{i}.stack) + message = sprintf('%s at %s (line %d)\n', message, varargin{i}.stack(j).name, varargin{i}.stack(j).line); + end + elseif isnumeric(varargin{i}) || isenum(varargin{i}) || islogical(varargin{i}) + message = strcat(message, string(varargin{i})); + elseif ischar(varargin{i}) || isstring(varargin{i}) + message = strcat(message, varargin{i}); + else + message = strcat(message, 'Unsupported data type'); + end + if i < numel(varargin) + message = strcat(message, ", "); + end end + + fprintf(this.fid, '%s %s %s %s\n', current_time, level, script_name, message); end end methods(Access=public) - function trace(this, message) - this.log("TRACE", message); + function trace(this, varargin) + this.log('TRACE', varargin{:}); end - function debug(this, message) - this.log("DEBUG", message); + function debug(this, varargin) + this.log('DEBUG', varargin{:}); end - function info(this, message) - this.log("INFO", message); + function info(this, varargin) + this.log('INFO', varargin{:}); end - function warning(this, message) - this.log("WARNING", message); + function warning(this, varargin) + this.log('WARNING', varargin{:}); end - function error(this, message) - this.log("ERROR", message); + function error(this, varargin) + this.log('ERROR', varargin{:}); end function delete(this) diff --git a/octave/logging/base_logger.m b/octave/logging/base_logger.m index 101ee18..a399833 100644 --- a/octave/logging/base_logger.m +++ b/octave/logging/base_logger.m @@ -34,19 +34,24 @@ % % delete() - Destructor method that closes the file identifier when the logger is deleted. % -% Example usage: +% Example Usage: % logger = base_logger.getInstance(); -% logger.info('This is an info message'); -% logger.error('This is an error message'); +% logger.info('Some info') +% +% try +% error('Simulated error for stack trace logging'); +% catch err +% logger.error('An error occurred:', err); +% end % % See also: fopen, fclose, dbstack, fprintf classdef base_logger < handle - properties(Access=private) + properties fid; end - - methods(Static, Access = public) + + methods(Static) function obj = getInstance() persistent instance; if isempty(instance) @@ -56,15 +61,15 @@ classdef base_logger < handle end end - methods(Access=private) + methods function this = base_logger() - this.fid = fopen(getenv("DEFAULT_LOG_PATH"), 'a'); + this.fid = fopen(getenv("APP_LOG_FILE"), 'a'); if this.fid == -1 - error('Failed to open log file: application.log'); + error('Failed to open log file'); end end - function log(this, level, message) + function log(this, level, varargin) current_time = strftime('%Y-%m-%d %H:%M:%S', localtime(time())); stack = dbstack('-completenames'); if length(stack) > 2 @@ -73,33 +78,47 @@ classdef base_logger < handle script_name = 'Unknown'; end - if this.fid ~= -1 - fprintf(this.fid, '%s %s %s %s\n', char(current_time), level, script_name, message); - else - error('File identifier is invalid. Cannot write to log.'); + message = sprintf(''); + for i = 1:numel(varargin) + if isstruct(varargin{i}) && isfield(varargin{i}, 'message') && isfield(varargin{i}, 'stack') + error_info = varargin{i}; + message = sprintf('%sError: %s\n', message, error_info.message); + for j = 1:length(error_info.stack) + message = sprintf('%s at %s (line %d)\n', message, error_info.stack(j).name, error_info.stack(j).line); + end + elseif isnumeric(varargin{i}) || islogical(varargin{i}) + message = sprintf('%s%s', message, num2str(varargin{i})); + elseif ischar(varargin{i}) || isstring(varargin{i}) + message = sprintf('%s%s', message, varargin{i}); + else + message = sprintf('%sUnsupported data type', message); + end + if i < numel(varargin) + message = sprintf('%s, ', message); + end end - end - end - methods(Access=public) - function trace(this, message) - this.log("TRACE", message); + fprintf(this.fid, '%s %s %s %s\n', current_time, level, script_name, message); end - function debug(this, message) - this.log("DEBUG", message); + function trace(this, varargin) + this.log('TRACE', varargin{:}); end - function info(this, message) - this.log("INFO", message); + function debug(this, varargin) + this.log('DEBUG', varargin{:}); end - function warning(this, message) - this.log("WARNING", message); + function info(this, varargin) + this.log('INFO', varargin{:}); end - function error(this, message) - this.log("ERROR", message); + function warning(this, varargin) + this.log('WARNING', varargin{:}); + end + + function error(this, varargin) + this.log('ERROR', varargin{:}); end function delete(this) diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py index e4af80b..53c229a 100644 --- a/python/logging/base_logger.py +++ b/python/logging/base_logger.py @@ -46,7 +46,7 @@ def getDefaultLogger(name): """ logger = logging.getLogger(name) if not logger.hasHandlers(): - file_handler = logging.FileHandler(os.environ['DEFAULT_LOG_PATH'], mode='a') + file_handler = logging.FileHandler(os.environ['APP_LOG_FILE'], mode='a') formatter = logging.Formatter('%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s') file_handler.setFormatter(formatter) logger.addHandler(file_handler) From 68e32149cc7a80e3d6e1cd3d9ee96c0e5aac9f87 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Mon, 30 Sep 2024 23:59:43 +0200 Subject: [PATCH 3/8] ISEPOS-2280 Adjusted example in python base logger --- python/logging/base_logger.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py index 53c229a..480f5cb 100644 --- a/python/logging/base_logger.py +++ b/python/logging/base_logger.py @@ -42,6 +42,10 @@ def getDefaultLogger(name): -------- logger = getDefaultLogger(__name__) logger.info("This is an info message.") + try: + raise Exception('Exception for example.') + except Exception as e: + logger.error('An error occurred:', exc_info=True) # Log with stack trace """ logger = logging.getLogger(name) From 03616dcac60b8f5491eaf3d2f05035d6a6350da7 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Thu, 3 Oct 2024 08:40:42 +0200 Subject: [PATCH 4/8] ISEPOS-2280 Adjusted examples of base logger usage --- matlab/logging/base_logger.m | 2 +- octave/logging/base_logger.m | 2 +- python/logging/base_logger.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matlab/logging/base_logger.m b/matlab/logging/base_logger.m index 1468182..b98d68c 100644 --- a/matlab/logging/base_logger.m +++ b/matlab/logging/base_logger.m @@ -39,7 +39,7 @@ % logger.info('Some info') % % try -% error('Simulated error for stack trace logging'); +% % some code causing exception % catch err % logger.error('An error occurred:', err); % end diff --git a/octave/logging/base_logger.m b/octave/logging/base_logger.m index a399833..70f62fc 100644 --- a/octave/logging/base_logger.m +++ b/octave/logging/base_logger.m @@ -39,7 +39,7 @@ % logger.info('Some info') % % try -% error('Simulated error for stack trace logging'); +% % some code causing exception % catch err % logger.error('An error occurred:', err); % end diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py index 480f5cb..b4234d8 100644 --- a/python/logging/base_logger.py +++ b/python/logging/base_logger.py @@ -43,9 +43,9 @@ def getDefaultLogger(name): logger = getDefaultLogger(__name__) logger.info("This is an info message.") try: - raise Exception('Exception for example.') - except Exception as e: - logger.error('An error occurred:', exc_info=True) # Log with stack trace + # some code causing exception + except Exception: + logger.exception('An error occurred') """ logger = logging.getLogger(name) From 0d0285a296c7bd113ce6a654f78b6a2f329b7b75 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Tue, 15 Oct 2024 08:38:55 +0200 Subject: [PATCH 5/8] ISEPOS-2280 Adjusted log file name in comment --- python/logging/base_logger.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py index b4234d8..a0f7067 100644 --- a/python/logging/base_logger.py +++ b/python/logging/base_logger.py @@ -11,7 +11,7 @@ def getDefaultLogger(name): Retrieves or creates a logger with the specified name and sets it up with a file handler. The logger is configured to write log messages to the file path specified by the - 'DEFAULT_LOG_PATH' environment variable. It uses the 'INFO' level as the default + 'APP_LOG_FILE' environment variable. It uses the 'INFO' level as the default logging level and writes log entries in the following format: 'YYYY-MM-DD HH:MM:SS,ms LEVEL logger_name message' @@ -30,13 +30,13 @@ def getDefaultLogger(name): -------- logger : logging.Logger A logger instance with the specified name. The logger is configured with a - file handler that writes to the file specified by the 'DEFAULT_LOG_PATH' + file handler that writes to the file specified by the 'APP_LOG_FILE' environment variable. Raises: ------- KeyError: - If the 'DEFAULT_LOG_PATH' environment variable is not set. + If the 'APP_LOG_FILE' environment variable is not set. Example: -------- From 13e4fa808f24664fab0aca0e78fd7a59c1d109f3 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Tue, 15 Oct 2024 11:55:59 +0200 Subject: [PATCH 6/8] ISEPOS-2280 Added fallback paths for base loggers --- matlab/logging/base_logger.m | 6 +++++- octave/logging/base_logger.m | 6 +++++- python/logging/base_logger.py | 21 ++++++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/matlab/logging/base_logger.m b/matlab/logging/base_logger.m index b98d68c..5fffdca 100644 --- a/matlab/logging/base_logger.m +++ b/matlab/logging/base_logger.m @@ -63,7 +63,11 @@ classdef base_logger < handle methods(Access=private) function this = base_logger() - this.fid = fopen(getenv("APP_LOG_FILE"), 'a'); + logFileName = getenv("APP_LOG_FILE"); + if isempty(logFileName) + logFileName = 'fallbackPathApplication.log'; + end + this.fid = fopen(logFileName, 'a'); if this.fid == -1 error('Failed to open log file'); end diff --git a/octave/logging/base_logger.m b/octave/logging/base_logger.m index 70f62fc..7e86da9 100644 --- a/octave/logging/base_logger.m +++ b/octave/logging/base_logger.m @@ -63,7 +63,11 @@ classdef base_logger < handle methods function this = base_logger() - this.fid = fopen(getenv("APP_LOG_FILE"), 'a'); + logFileName = getenv("APP_LOG_FILE"); + if isempty(logFileName) + logFileName = 'fallbackPathApplication.log'; + end + this.fid = fopen(logFileName, 'a'); if this.fid == -1 error('Failed to open log file'); end diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py index a0f7067..16f6f0b 100644 --- a/python/logging/base_logger.py +++ b/python/logging/base_logger.py @@ -11,8 +11,10 @@ def getDefaultLogger(name): Retrieves or creates a logger with the specified name and sets it up with a file handler. The logger is configured to write log messages to the file path specified by the - 'APP_LOG_FILE' environment variable. It uses the 'INFO' level as the default - logging level and writes log entries in the following format: + 'APP_LOG_FILE' environment variable. If the environment variable is not set, + the logger will write to the file 'fallbackPathApplication.log' in the current + working directory. The logger uses the 'INFO' level as the default logging level + and writes log entries in the following format: 'YYYY-MM-DD HH:MM:SS,ms LEVEL logger_name message' @@ -31,12 +33,8 @@ def getDefaultLogger(name): logger : logging.Logger A logger instance with the specified name. The logger is configured with a file handler that writes to the file specified by the 'APP_LOG_FILE' - environment variable. - - Raises: - ------- - KeyError: - If the 'APP_LOG_FILE' environment variable is not set. + environment variable, or to 'fallbackPathApplication.log' if the environment + variable is not set. Example: -------- @@ -47,10 +45,15 @@ def getDefaultLogger(name): except Exception: logger.exception('An error occurred') + Notes: + ------ + - The 'APP_LOG_FILE' environment variable should specify the full path to the log file. + - If 'APP_LOG_FILE' is not set, logs will be written to 'fallbackPathApplication.log'. + """ logger = logging.getLogger(name) if not logger.hasHandlers(): - file_handler = logging.FileHandler(os.environ['APP_LOG_FILE'], mode='a') + file_handler = logging.FileHandler(os.environ.get('APP_LOG_FILE', 'fallbackPathApplication.log'), mode='a') formatter = logging.Formatter('%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s') file_handler.setFormatter(formatter) logger.addHandler(file_handler) From 7ba8869df02b58c5ceb8bb21dd81e5694e40a350 Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Tue, 15 Oct 2024 16:50:30 +0200 Subject: [PATCH 7/8] ISEPOS-2280 Adjusted fallback log name --- matlab/logging/base_logger.m | 2 +- octave/logging/base_logger.m | 2 +- python/logging/base_logger.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/matlab/logging/base_logger.m b/matlab/logging/base_logger.m index 5fffdca..09f8a66 100644 --- a/matlab/logging/base_logger.m +++ b/matlab/logging/base_logger.m @@ -65,7 +65,7 @@ classdef base_logger < handle function this = base_logger() logFileName = getenv("APP_LOG_FILE"); if isempty(logFileName) - logFileName = 'fallbackPathApplication.log'; + logFileName = 'base-logger-log.log'; end this.fid = fopen(logFileName, 'a'); if this.fid == -1 diff --git a/octave/logging/base_logger.m b/octave/logging/base_logger.m index 7e86da9..503bc11 100644 --- a/octave/logging/base_logger.m +++ b/octave/logging/base_logger.m @@ -65,7 +65,7 @@ classdef base_logger < handle function this = base_logger() logFileName = getenv("APP_LOG_FILE"); if isempty(logFileName) - logFileName = 'fallbackPathApplication.log'; + logFileName = 'base-logger-log.log'; end this.fid = fopen(logFileName, 'a'); if this.fid == -1 diff --git a/python/logging/base_logger.py b/python/logging/base_logger.py index 16f6f0b..188b72f 100644 --- a/python/logging/base_logger.py +++ b/python/logging/base_logger.py @@ -12,7 +12,7 @@ def getDefaultLogger(name): The logger is configured to write log messages to the file path specified by the 'APP_LOG_FILE' environment variable. If the environment variable is not set, - the logger will write to the file 'fallbackPathApplication.log' in the current + the logger will write to the file 'base-logger-log.log' in the current working directory. The logger uses the 'INFO' level as the default logging level and writes log entries in the following format: @@ -33,7 +33,7 @@ def getDefaultLogger(name): logger : logging.Logger A logger instance with the specified name. The logger is configured with a file handler that writes to the file specified by the 'APP_LOG_FILE' - environment variable, or to 'fallbackPathApplication.log' if the environment + environment variable, or to 'base-logger-log.log' if the environment variable is not set. Example: @@ -48,12 +48,12 @@ def getDefaultLogger(name): Notes: ------ - The 'APP_LOG_FILE' environment variable should specify the full path to the log file. - - If 'APP_LOG_FILE' is not set, logs will be written to 'fallbackPathApplication.log'. + - If 'APP_LOG_FILE' is not set, logs will be written to 'base-logger-log.log'. """ logger = logging.getLogger(name) if not logger.hasHandlers(): - file_handler = logging.FileHandler(os.environ.get('APP_LOG_FILE', 'fallbackPathApplication.log'), mode='a') + file_handler = logging.FileHandler(os.environ.get('APP_LOG_FILE', 'base-logger-log.log'), mode='a') formatter = logging.Formatter('%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s') file_handler.setFormatter(formatter) logger.addHandler(file_handler) From be2d4ffa36977f85d34269ac5993259e064460dc Mon Sep 17 00:00:00 2001 From: plgmlesniak Date: Tue, 15 Oct 2024 20:43:18 +0200 Subject: [PATCH 8/8] ISEPOS-2280 Adjusted javadoc of newer matlab and octave logger versions --- matlab/logging/base_logger.m | 23 +++++++++++++---------- octave/logging/base_logger.m | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/matlab/logging/base_logger.m b/matlab/logging/base_logger.m index 09f8a66..516c1df 100644 --- a/matlab/logging/base_logger.m +++ b/matlab/logging/base_logger.m @@ -10,6 +10,9 @@ % It follows the Singleton pattern to ensure that only one instance of the logger % exists throughout the application. % +% The log file is specified by the environment variable 'APP_LOG_FILE'. If +% the variable is not set, a default file 'base-logger-log.log' is used. +% % Properties: % fid - (private) The file identifier for the log file. This is used to write logs. % @@ -17,20 +20,20 @@ % % getInstance() - Retrieves the singleton instance of the logger. % -% trace(message) - Logs a message with TRACE level. -% @param message The message to log. +% trace(varargin) - Logs one or more messages with TRACE level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% debug(message) - Logs a message with DEBUG level. -% @param message The message to log. +% debug(varargin) - Logs one or more messages with DEBUG level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% info(message) - Logs a message with INFO level. -% @param message The message to log. +% info(varargin) - Logs one or more messages with INFO level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% warning(message) - Logs a message with WARNING level. -% @param message The message to log. +% warning(varargin) - Logs one or more messages with WARNING level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% error(message) - Logs a message with ERROR level. -% @param message The message to log. +% error(varargin) - Logs one or more messages with ERROR level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % % delete() - Destructor method that closes the file identifier when the logger is deleted. % diff --git a/octave/logging/base_logger.m b/octave/logging/base_logger.m index 503bc11..3ef3da1 100644 --- a/octave/logging/base_logger.m +++ b/octave/logging/base_logger.m @@ -10,6 +10,9 @@ % It follows the Singleton pattern to ensure that only one instance of the logger % exists throughout the application. % +% The log file is specified by the environment variable 'APP_LOG_FILE'. If +% the variable is not set, a default file 'base-logger-log.log' is used. +% % Properties: % fid - (private) The file identifier for the log file. This is used to write logs. % @@ -17,20 +20,20 @@ % % getInstance() - Retrieves the singleton instance of the logger. % -% trace(message) - Logs a message with TRACE level. -% @param message The message to log. +% trace(varargin) - Logs one or more messages with TRACE level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% debug(message) - Logs a message with DEBUG level. -% @param message The message to log. +% debug(varargin) - Logs one or more messages with DEBUG level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% info(message) - Logs a message with INFO level. -% @param message The message to log. +% info(varargin) - Logs one or more messages with INFO level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% warning(message) - Logs a message with WARNING level. -% @param message The message to log. +% warning(varargin) - Logs one or more messages with WARNING level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % -% error(message) - Logs a message with ERROR level. -% @param message The message to log. +% error(varargin) - Logs one or more messages with ERROR level. +% @param varargin The messages to log. Can be strings, numbers, or MException objects. % % delete() - Destructor method that closes the file identifier when the logger is deleted. %