-
Notifications
You must be signed in to change notification settings - Fork 21
Adding setLogLevel feature #264
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
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.
| 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()) { |
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.
Pull Request Overview
This PR introduces dynamic log level filtering functionality to the mesh logging system, allowing runtime adjustment of the minimum log level that will be displayed.
- Adds
setLogLevelfunction to dynamically control log filtering at runtime - Implements level checking in both Logger constructor and destructor to prevent unnecessary message processing
- Updates Logger move constructor and operator() method to store and check log levels properly
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| media-proxy/src/mesh/logger.cc | Implements log level filtering logic and setLogLevel function |
| media-proxy/include/mesh/logger.h | Adds public API declarations and comprehensive documentation with examples |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| if (!ostream.str().empty()) | ||
| Logger::~Logger() { | ||
| if (!ostream.str().empty() && level >= currentLogLevel) { |
Copilot
AI
Aug 27, 2025
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.
The variable level is not accessible in the destructor scope. The Logger class needs to store the level as a member variable, but the destructor is trying to access an undefined level variable.
| * Output: | ||
| * Nov 15 00:26:07.672 [WARN] Low memory warning available_mb=512 | ||
| * Nov 15 00:26:07.672 [ERRO] Critical error occurred error_code=5001 | ||
| * Nov 15 00:26:07.672 [DEBU] Debugging details step=init |
Copilot
AI
Aug 27, 2025
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.
The documentation shows debug messages being output when log level is set to warn, but debug messages should be filtered out since debug level is typically lower priority than warn level.
| * Nov 15 00:26:07.672 [DEBU] Debugging details step=init |
|
I suppose the logger functionality should be moved to And after that, this the log level feature could be added. |

mesh::log::setLogLevel(mesh::log::Level)to dynamically adjust log filtering.info,warn,error,debug,fatal.