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

Adding logger to SU2 #1991

Open
kursatyurt opened this issue Mar 28, 2023 · 2 comments
Open

Adding logger to SU2 #1991

kursatyurt opened this issue Mar 28, 2023 · 2 comments

Comments

@kursatyurt
Copy link
Contributor

kursatyurt commented Mar 28, 2023

There is a lot of boilerplate code in the code base for screen output like

 if (rank == MASTER_NODE) {
cout << "My Message" << endl;
}

This is not a good example from many points of view.

From performance-wise overly used std::endl is a killer. If one needs to redirect output to file it is additional loss etc.
From the user's perspective, it is not possible to set the logging level. At least a three-level logging would be nice (INFO/WARNING/DEBUG) this also makes life easier for developers too.

It is also nice to have a rotating log file if one runs longer cases on the HPC systems. After a while the log files getting so bloating

Describe the solution you'd like

A configurable logger would be better with defaults not changing the current system

% LOGGING LOCATIONS default is SCREEN
LOG= (SCREEN, FILE)
% Default  is SU2.log
LOG_FILE = "myLog.log"
% Logging level INFO/DEBUG 
LOG_LEVEL = "DEBUG" 

In the code

For general messages

INFO <<  "My useful information";
DEBUG << "Operation done in "  << time << " seconds";

There is also a lot of --------------- Start Solver ---------- type headers in the code we can automate this as

HEADER << "Start Solver"; 

Describe alternatives you've considered

A proper choice of logging library is required. Alternatives I considered:

AixLog

  • Header only
  • Vanilla C++11, no dependencies
  • Uses << operator
  • MIT licence

spdlog

  • Header only/compiled
  • C++11
  • Uses LOG("") syntax
  • More users/mature project
  • MIT licence

easylogging

  • Header only
  • C++11
  • Uses << operator
  • MIT licence

glog

  • C++14 required the codebase must be bumped (may not be worth it)
  • Uses << operator
  • Google Licence (IDK if it comp. with GPL)

I am in favor of spdlog library

Additional context
Add any other context or screenshots about the feature request here.

@pcarruscag
Copy link
Member

pcarruscag commented Mar 29, 2023

This is a nice-to-have but there are 2600 uses of cout << in SU2, are you sure you want to refactor all of them?
If you pick something with operator << it will be easier.

@kursatyurt
Copy link
Contributor Author

There are some tricks possible to add the << operator. Not all the code base needs refactoring. We can have both styles for the future as () syntax is very powerful thanks to fmtlib.

cout << "Values at node<< nodeId << " are " << val[0] << " " << val[1] << " " << val[3] << endl;

can be transformed directly to

LOG("Values at node {} are {}",nodeId,val);

Equivalently

LOG << fmt::format("Values at node {} are {}",nodeId,val); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants