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

Logging redesign - part 3 #1147

Merged
merged 7 commits into from
Sep 3, 2024
Merged

Logging redesign - part 3 #1147

merged 7 commits into from
Sep 3, 2024

Conversation

bcoconni
Copy link
Member

After some consolidation of the logging code (PR #1141, ##1142 and ##1145), this PR resumes the migration of the code to the new logging system.

I took this opportunity to:

  • Rename the member of FGLogging from level to log_level for more clarity and to avoid confusion with the method parameters of FGLogging which tend to be named level as well.
  • The minimum level feature has been moved from FGLogger to FGLogConsole as I think the implementation of this feature should not be imposed by the mother class FGLogger.
    • The unit test of FGLogConsole has been extended to check that the minimum logged level behave as intended.
    • The minimum logged level default is set to LogLevel::BULK so that it does not filter anything by default.

There are also a few white spaces changes because I've set my editor to remove trailing spaces before saving. Yes I'm that kind of person who can't resist taking care of this kind of futile details 😄

Copy link

codecov bot commented Aug 25, 2024

Codecov Report

Attention: Patch coverage is 4.27350% with 112 lines in your changes missing coverage. Please review.

Project coverage is 25.12%. Comparing base (f33f20e) to head (b0e5e52).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/models/FGAerodynamics.cpp 0.00% 57 Missing ⚠️
src/models/FGExternalForce.cpp 0.00% 24 Missing ⚠️
src/models/FGAircraft.cpp 0.00% 16 Missing ⚠️
src/models/FGBuoyantForces.cpp 0.00% 5 Missing ⚠️
src/models/FGFCSChannel.h 0.00% 5 Missing ⚠️
src/models/FGAccelerations.cpp 0.00% 3 Missing ⚠️
src/models/FGMassBalance.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1147      +/-   ##
==========================================
- Coverage   25.13%   25.12%   -0.01%     
==========================================
  Files         170      170              
  Lines       18325    18337      +12     
==========================================
+ Hits         4606     4608       +2     
- Misses      13719    13729      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seanmcleod
Copy link
Member

Looks good.

One follow-up question, partly triggered by #834 (comment) in terms of state reports from notify sections in scripts.

When we update FGScript.cpp do these state reports requested by a user via a script naturally fall into our LogLevel?

enum class LogLevel {
BULK, // For frequent messages
DEBUG, // Less frequent debug type messages
INFO, // Informatory messages
WARN, // Possible impending problem
ERROR, // Problem that can be recovered
FATAL // Fatal problem => an exception will be thrown
};

Or are they separate from debug logging, with it's varying levels of debug detail/level?

@bcoconni
Copy link
Member Author

One follow-up question, partly triggered by #834 (comment) in terms of state reports from notify sections in scripts.

When we update FGScript.cpp do these state reports requested by a user via a script naturally fall into our LogLevel?

enum class LogLevel {
BULK, // For frequent messages
DEBUG, // Less frequent debug type messages
INFO, // Informatory messages
WARN, // Possible impending problem
ERROR, // Problem that can be recovered
FATAL // Fatal problem => an exception will be thrown
};

Or are they separate from debug logging, with it's varying levels of debug detail/level?

That's a good question.

All messages are meant to be processed by FGLogging to save having several classes. Maybe we could add an additional log level (USER ?) that has a higher priority than all the other log levels to guarantee it is always displayed ?

@bcoconni
Copy link
Member Author

And speaking about #834, I have just committed some changes to replace the occurrences of std::endl by \n. The changes are just applied to the files that were planned to be updated by this PR. The replacement of std::endl in the files that have been modified by the PRs #1094 and #1136 will be addressed in a separate PR

@seanmcleod
Copy link
Member

replace the occurrences of std::endl by \n.

Yep, I understand the performance reason, personally just find it more difficult to read the text in the editor with `\n' appended to the last word 😢

Not sure if the following compile time concatenation would be to the liking of other developers 😉

cout << " aircraft config file. (LIFT DRAG)\n";

cout << " aircraft config file. (LIFT DRAG)" "\n";

Maybe we could add an additional log level (USER ?) that has a higher priority than all the other log levels to guarantee it is always displayed?

Hmm, wondering whether we end up needing a bitmask approach?

@bcoconni
Copy link
Member Author

Not sure if the following compile time concatenation would be to the liking of other developers 😉

cout << " aircraft config file. (LIFT DRAG)\n";

cout << " aircraft config file. (LIFT DRAG)" "\n";

I have no strong opinion regarding this. Feel free to modify this PR branch (bcoconni/logging3) to your liking 😄

Maybe we could add an additional log level (USER ?) that has a higher priority than all the other log levels to guarantee it is always displayed?

Hmm, wondering whether we end up needing a bitmask approach?

What do you mean ? Can you detail your thoughts ?

@bcoconni
Copy link
Member Author

I've just pushed another commit to this PR to replace a couple of normint by LogLevel::NORMAL that have been overlooked in PR #1136.

@bcoconni
Copy link
Member Author

I have no strong opinion regarding this. Feel free to modify this PR branch (bcoconni/logging3) to your liking

Or alternatively you can create your own branch and I'll cherry pick your commits to reformat the \n's.

@seanmcleod
Copy link
Member

Or alternatively you can create your own branch and I'll cherry pick your commits to reformat the \n's.

Or should I wait for you to finish updating the whole code base to use the new logging mechanism, and then submit a PR that does this reformatting across the whole code base as a single commit?

@bcoconni
Copy link
Member Author

Or alternatively you can create your own branch and I'll cherry pick your commits to reformat the \n's.

Or should I wait for you to finish updating the whole code base to use the new logging mechanism, and then submit a PR that does this reformatting across the whole code base as a single commit?

Sounds good 👍

@seanmcleod
Copy link
Member

Maybe we could add an additional log level (USER ?) that has a higher priority than all the other log levels to guarantee it is always displayed?

Hmm, wondering whether we end up needing a bitmask approach?

What do you mean ? Can you detail your thoughts ?

So we currently have:

enum class LogLevel {
BULK, // For frequent messages
DEBUG, // Less frequent debug type messages
INFO, // Informatory messages
WARN, // Possible impending problem
ERROR, // Problem that can be recovered
FATAL // Fatal problem => an exception will be thrown
};

With a rough assumption of decreasing verbosity from BULK to FATAL (typically a maximum of 1 of these 😉) , so a JSBSim user/developer gets to set a minimum level via SetMinLevel(LogLevel). Which probably works for the vast majority of uses?

But I was wondering whether a user/developer may want to cherry pick, i.e. via a bitmask, e.g. selecting for example, DEBUG, WARN, ERROR, FATAL.

@bcoconni
Copy link
Member Author

bcoconni commented Sep 2, 2024

With a rough assumption of decreasing verbosity from BULK to FATAL (typically a maximum of 1 of these 😉) , so a JSBSim user/developer gets to set a minimum level via SetMinLevel(LogLevel). Which probably works for the vast majority of uses?

But I was wondering whether a user/developer may want to cherry pick, i.e. via a bitmask, e.g. selecting for example, DEBUG, WARN, ERROR, FATAL.

I agree that the method FGLogConsole::SetMinLevel() has extremely basic capabilities at filtering the log messages but this can be changed later on.

As you mentioned, different users may have very different needs and for that very reason I think that filtering strategies must not be dictated from the top by the FGLogging class but entirely delegated to the inherited class.

That being said, if we want to allow using a bitmask, I think it's possible to attribute power of 2's values to each element of enum class LogLevel, something like:

 enum class LogLevel { 
   BULK  = 1,  // For frequent messages 
   DEBUG = 2,  // Less frequent debug type messages 
   INFO  = 4,  // Informatory messages 
   WARN  = 8,  // Possible impending problem 
   ERROR = 16, // Problem that can be recovered 
   FATAL = 32  // Fatal problem => an exception will be thrown 
 };

@agodemar
Copy link
Contributor

agodemar commented Sep 3, 2024

Will we merge this PR? @bcoconni

@bcoconni bcoconni merged commit e607c27 into JSBSim-Team:master Sep 3, 2024
29 checks passed
@bcoconni
Copy link
Member Author

bcoconni commented Sep 3, 2024

Will we merge this PR? @bcoconni

Yes, sure. Done ! 😉

@bcoconni bcoconni deleted the logging3 branch September 3, 2024 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants