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

Fix compiler warnings and condition check improvements #390

Merged
merged 4 commits into from
Nov 24, 2020

Conversation

alvin-777
Copy link
Contributor

@alvin-777 alvin-777 commented Nov 20, 2020

  • TDD

New/modified code must be backed down with unit test - preferably TDD style development)

  • Documentation

All new/modified functionality should be backed up with API documentation (API.markdown or README.markdown)

Cross-Platform Testing

  • Travis-CI (Linux, OSX) + AppVeyor-CI (Windows)\
  • Optional: Local/VM testing: Windows
  • Optional: Local/VM testing: OSX
  • Optional: Local/VM testing: Linux

Testing Advice

mkdir build; cd build; cmake -DADD_G3LOG_UNIT_TEST=ON ..

Run Test Alternatives:

  • Cross-Platform: ctest
  • or ctest -V for verbose output
  • Linux: make test

Fix compiler warnings

  • loglevels.cpp - warns about double return if dynamic logging is on
  • crashhandler_unix.cpp - warns about unused variable

Condition check improvements

  1. Make the condition check more "C++ intuitive" (reverted)

For example, people may do something like below:

// log the value if pointer is not null
LOG_IF(DEBUG, ptr) << "value: " << ptr->val;

This would not work since ptr != true, and would possibly confuse them

  1. Checking if log level is enabled first.
    If it's disabled, there's no need to evaluate the expression (which can be expensive)

- loglevels.cpp - warns about double return if dynamic logging is on
- crashhandler_unix.cpp - warns about unused variable
1. Make the condition check more "C++ intuitive"

For example, people may do something like below:
```cpp
// log the value if pointer is not null
LOG_IF(DEBUG, ptr) << "value: " << ptr->val;
```
This would not work since `ptr != true`, and would possibly confuse them

2. Checking if log level is enabled first.
If it's disabled, there's no need to evaluate the expression (which can be expensive)
src/crashhandler_unix.cpp Show resolved Hide resolved
src/g3log/g3log.hpp Show resolved Hide resolved
src/g3log/g3log.hpp Outdated Show resolved Hide resolved
src/loglevels.cpp Show resolved Hide resolved
Copy link
Contributor Author

@alvin-777 alvin-777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 is reverted
2 I believe it's necessary

src/g3log/g3log.hpp Outdated Show resolved Hide resolved
@alvin-777 alvin-777 requested a review from KjellKod November 23, 2020 12:28
@@ -145,17 +145,17 @@ namespace g3 {


// LOG(level) is the API for the stream log
#define LOG(level) if(!g3::logLevel(level)) {} else INTERNAL_LOG_MESSAGE(level).stream()
#define LOG(level) if (!g3::logLevel(level)) {} else INTERNAL_LOG_MESSAGE(level).stream()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format change with my “space” change not yet removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place you didn't put a space after an if.
Are you sure that you want to keep it inconsistent with everywhere else?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. For this file. Leave this as is. Thanks for calling it out

src/g3log/g3log.hpp Outdated Show resolved Hide resolved
src/g3log/g3log.hpp Outdated Show resolved Hide resolved
src/g3log/g3log.hpp Outdated Show resolved Hide resolved
@KjellKod KjellKod merged commit 2fca06f into KjellKod:master Nov 24, 2020
alvin-777 added a commit to alvin-777/g3log that referenced this pull request Nov 25, 2020
Fix compiler warnings and condition check improvements (KjellKod#390)
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.

2 participants