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

Add QUILL_SHOULD_LOG macro #187

Closed
fhriley opened this issue Aug 24, 2022 · 1 comment · Fixed by #192
Closed

Add QUILL_SHOULD_LOG macro #187

fhriley opened this issue Aug 24, 2022 · 1 comment · Fixed by #192

Comments

@fhriley
Copy link

fhriley commented Aug 24, 2022

Currently, to conditionally do some processing before logging, you do it like this:

if (logger->should_log(LogLevel::TraceL1)) {
  ... // do some processing
  LOG_TRACE_L1(logger, ...);
}

If QUILL_ACTIVE_LOG_LEVEL is set to QUILL_LOG_LEVEL_DEBUG or higher, the LOG_TRACE_L1 will not be compiled in, but the remaining code will be. It seems like there should be a macro instead such that the code above becomes:

if (QUILL_SHOULD_LOG(logger, LogLevel::TraceL1)) {
  ... // do some processing
  LOG_TRACE_L1(logger, ...);
}

The macro would just evaluate to false when QUILL_ACTIVE_LOG_LEVEL is set to QUILL_LOG_LEVEL_DEBUG or higher.

@odygrd
Copy link
Owner

odygrd commented Sep 23, 2022

hello, thanks for reporting.

A compile time check has been added to logger->should_log<level>()

previous logger->should_log(level) has now been removed to avoid confusion.

The below should have equivalent behaviour to the requested SHOULD_LOG macro :

if (logger->should_log<LogLevel::TraceL1>()) {
  ... // do some processing
  LOG_TRACE_L1(logger, ...);
}```

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 a pull request may close this issue.

2 participants