-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
[RFC] Introducing level_filter
concept
#2716
Comments
The // For backward-compatibility
- level_filter(level_enum level) {
- return level_filter::more_severe_equal(level);
- }
+ level_filter(level_enum level) : level_filter(condition::more_severe_equal, level) {} |
@tt4g Good catch! Code updated. |
IMO. If this feature is added, someone will want equivalent features in the following APIs:
spdlog/include/spdlog/sinks/sink.h Line 22 in c65aa4e
Remember that one of the reasons ABI breaks is that the type of spdlog/include/spdlog/sinks/sink.h Lines 25 to 28 in c65aa4e
|
Thanks for the RFC. Might be useful to avoid confusions regarding log levels, however it might be an overkill with too many options. Most users just want to set the log level and forget about it.
Right, checking log level is the absolute hottest path in spdlog, extra care should be taken. For example a table of produced when the
and the bool should_log(level::level_enum msg_level) const
{
auto my_level = level_.load(std::memory_order_relaxed);
return lookup_table[my_level][msg_level];
} Of course, there is a good chance it is not any faster or even slower than the |
Was there a pull request introducing these features? I can't find it, or the features mentioned. |
@cppcooper No PR has implemented this proposal. |
Summary
This issue proposes a new concept
level_filter
to distinguish from the existingenum level_enum
. It is inspired by my implementingspdlog-rs
https://github.com/SpriteOvO/spdlog-rs/blob/f076b7d08fc0fe067389b27461c8bbade6144d3f/spdlog/src/level.rs#L185-L223, which is designed to hide the numerical relationships between levels.Motivation
Currently, we only use
enum level_enum
to represent levels of records and levels of filters. It causes some confusion and inconveniences, for example:level_a < level_b
andsink.set_level(level::error)
is non-intuitive for newbies unfamiliar with this library. Who is smaller,info
orerr
?write error and critical logs to stderr #345 is impossible in the current design unless users implement a custom sink.
With this new concept added, users can be flexible manipulate the levels of filters for complex conditions to implement something like the issue #345 mentioned above and write intuitive code in this way:
Guide-level explanation
Basically, the new concept is supposed to use like:
This proposal expects not to break something for most use cases. So that users can still use the old way to set levels. When should users use the new way?
Reference-level explanation
There are 2 possible implementations I can imagine.
Pseudo-code:
Or
Then replace
level_enum
withlevel_filter
where they have filter semantics. e.g.Drawbacks
Implementing this proposal contains breaking changes eventually (e.g. for sinks are implemented by users manually, since the type of parameter has changed), however, we could add it in v2.x.
It also brings more overhead compared to the old way, but it is not expected to be significant. The more overhead of the first possible implementation may just be that the functions cannot be inline.
Future possibilities
If we decide to add it in v2.x, we could also consider if it's necessary to remove the old way completely (rename
set_level
toset_level_filter
to avoid confusion, removing the backward-compatibility tricks and enumeratorlevel_enum::off
, etc.).The text was updated successfully, but these errors were encountered: