ISEPOS-2280 Added base loggers scripts #1
Loadingβ¦
Reference in New Issue
Block a user
No description provided.
Delete Branch "ymlesni/shared-snippets:feature/ISEPOS-2280-mechanizm-raportowania-informacji-z-aplikacji-do-pliku-z-logami"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
General Information
Changes made / Cause of error / Reason for refactoring and solution
Added simple base logger scripts for matlab, octave and python.
Related pull requests
Do we need separate scripts for Octave and Matlab? Are they different?
@ -0,0 +37,4 @@
% Example usage:
% logger = base_logger.getInstance();
% logger.info('This is an info message');
% logger.error('This is an error message');
Can we put here an example with error object? So that the stack trace of the exception gets logged.
Base logger has been enchanced and example for error logging has been added.
@ -0,0 +41,4 @@
Example:
--------
logger = getDefaultLogger(__name__)
logger.info("This is an info message.")
An example with an error with logging stack trace would be convenient here
Example for error with stack trace logging has been added.
@ -0,0 +45,4 @@
try:
raise Exception('Exception for example.')
except Exception as e:
logger.error('An error occurred:', exc_info=True) # Log with stack trace
We have
except Exception as e
but thee
is not used anywhere... is this correct?Maybe it is good to use here the
logger.exception()
(doc) method as a showcase.e
could be used to process exception further, but it is not necessary for example, I will remove it.Would adding
logger.exception()
as a additional option be a good idea (to still showcase how to log exception at chosen log level)? For now I will change tologger.exception()
.@ -0,0 +43,4 @@
logger = getDefaultLogger(__name__)
logger.info("This is an info message.")
try:
raise Exception('Exception for example.')
Maybe just put here some placeholder meaning that this is a code that may produce an error
Ok, I will do the same for Matlab and Octave versions.
@ -0,0 +11,4 @@
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
I think the name was changed to 'APP_LOG_FILE'
@ -0,0 +36,4 @@
Raises:
-------
KeyError:
If the 'DEFAULT_LOG_PATH' environment variable is not set.
Here, again, the name of the variable should be updated. But I thought also that instead of throwing an error, we might use some default file name, to allow users to run the app also outside of the platform. But, I would set the default log file name to something different than "application.log", so that we know that we could notice if something is wrong with setting the environment variable.
@ -0,0 +65,4 @@
function this = base_logger()
logFileName = getenv("APP_LOG_FILE");
if isempty(logFileName)
logFileName = 'fallbackPathApplication.log';
Can we use a different name? Something that we would consider a log file at first glance ('fallbackPath' is something I wouldn't) - if we don't want to make it too simple, to avoid name collision with other things, maybe e.g. base-app-log.log or base-logger-log.log or something like that