Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger #210

Merged
merged 3 commits into from
Oct 22, 2022
Merged

Logger #210

merged 3 commits into from
Oct 22, 2022

Conversation

ardasener
Copy link
Contributor

@ardasener ardasener commented Oct 20, 2022

This PR adds a Logger class to the utils namespace.

The structure of the log messages is the following:

[TIME] [LEVEL] [SOURCE] MESSAGE

TIME is a date and time string. Note that this uses the locale so could differ from system to system.

LEVEL can be INFO or WARNING. Other levels can be easily added later if need be. Note that ERROR is not implemented as those should be exceptions instead. DEBUG is also not implemented as ideally that would be turned on/off in compile time; this could be implemented later as a separate function.

SOURCE will typically be the demangled class name however developers can customize it if needed.

Here is an example:

[10/21/22 00:10:51] [WARNING] [sparsebase::format::CSR<unsigned int, unsigned int, unsigned int>] CSR column array must be sorted. Sorting...

Developers can use the Logger as shown here:

utils::Logger logger(typeid(this));
logger.Log("COO arrays must be sorted. Sorting...", utils::LOG_LVL_WARNING);

Instead of typeid(this) the developer can also pass an arbitrary string. This is used to show the source field in the log message.

Users can adjust various aspects of the logging. Here is an example:

// Doesn't log INFO level events
utils::Logger::set_level(utils::LOG_LVL_WARNING); 

// Write to file as well as print
utils::Logger::set_file("test.log");

// Use stderr instead of stdout
utils::Logger::set_stdout(false);
utils::Logger::set_stderr(true);

@ardasener ardasener added priority: soon High priority state: pending Taking action type: feature Brand new functionality, features, workflows, endpoints, etc labels Oct 20, 2022
@AmroAlJundi AmroAlJundi linked an issue Oct 21, 2022 that may be closed by this pull request
@AmroAlJundi
Copy link
Contributor

AmroAlJundi commented Oct 22, 2022

Have you considered using the observer pattern? This way we could add more output channels. This might be too looking ahead but this would allow us to log into a socket for example.

Each level can have its own subscribers list and it can by default by initialized to the standard ones.

@Atahanak
Copy link
Collaborator

I dug around and found the following, Design Patterns for logging, I believe for milestone 3 current logging ability is okay. We may need to advance it in future releases.

@ardasener
Copy link
Contributor Author

I dug around and found the following, Design Patterns for logging, I believe for milestone 3 current logging ability is okay. We may need to advance it in future releases.

I did use chain of responsibility before for logging in another project. But here it felt overly complex. However, we can implement that later if we need to.

@ardasener ardasener merged commit 051dba9 into develop Oct 22, 2022
@ardasener ardasener deleted the feature/logger branch October 22, 2022 10:10
SinanEkm pushed a commit that referenced this pull request Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: soon High priority state: pending Taking action type: feature Brand new functionality, features, workflows, endpoints, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging support (verbosity in the library)
3 participants