-
Notifications
You must be signed in to change notification settings - Fork 20
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 setLogLevel feature #264
base: main
Are you sure you want to change the base?
Conversation
* Features: * - Use `mesh::log::setLogLevel(mesh::log::Level)` to dynamically adjust log filtering. * - Supported log levels: `info`, `warn`, `error`, `debug`, `fatal`. * - Messages below the set log level will be ignored.
Logger(const Logger&) = delete; | ||
Logger& operator=(const Logger&) = delete; | ||
~Logger(); | ||
|
||
template<typename T> | ||
Logger& operator()(const char *key, const T& value) { | ||
if (formatter) | ||
if (formatter && level >= currentLogLevel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still print the log message here no matter which log level is set, right? You only avoid formatter methods to be called if the level is disabled.
void setLogLevel(Level level) { | ||
currentLogLevel = level; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not thread-safe. Since there is no meaning in changing the log level at runtime, I suggest to leave this function as it is but say in the comment block that this is to be called only once the logger is created in the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there was a meaning for me - for different tests I wanted to have control over what is visible where, I'll make it thread safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make it thread safe, you'll make currentLogLevel
thread safe. It will add latency to printing messages. Please don't.
|
||
if (!ostream.str().empty()) | ||
Logger::~Logger() { | ||
if (!ostream.str().empty() && level >= currentLogLevel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!ostream.str().empty() && level >= currentLogLevel) { | |
if (level >= currentLogLevel && !ostream.str().empty()) { |
mesh::log::setLogLevel(mesh::log::Level)
to dynamically adjust log filtering.info
,warn
,error
,debug
,fatal
.