Skip to content

Conversation

@moleksy
Copy link
Collaborator

@moleksy moleksy commented Nov 22, 2024

  • 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.

 * 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.
@moleksy
Copy link
Collaborator Author

moleksy commented Nov 22, 2024

How it works:
image

template<typename T>
Logger& operator()(const char *key, const T& value) {
if (formatter)
if (formatter && level >= currentLogLevel)
Copy link
Collaborator

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.

Comment on lines +118 to +120
void setLogLevel(Level level) {
currentLogLevel = level;
}
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (!ostream.str().empty() && level >= currentLogLevel) {
if (level >= currentLogLevel && !ostream.str().empty()) {

Copilot AI review requested due to automatic review settings August 27, 2025 08:34
Copy link
Contributor

Copilot AI left a 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 setLogLevel function 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) {
Copy link

Copilot AI Aug 27, 2025

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.

Copilot uses AI. Check for mistakes.
* 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
Copy link

Copilot AI Aug 27, 2025

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.

Suggested change
* Nov 15 00:26:07.672 [DEBU] Debugging details step=init

Copilot uses AI. Check for mistakes.
@ko80
Copy link
Collaborator

ko80 commented Aug 27, 2025

I suppose the logger functionality should be moved to shared first
https://github.com/OpenVisualCloud/Media-Communications-Mesh/tree/zero-copy-2/shared

And after that, this the log level feature could be added.

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.

3 participants