Skip to content

Commit bd130b6

Browse files
Demonstrate reading per-module and global log levels in example.
Also correct problem reading global log level from the module logger class interface.
1 parent 3339e8c commit bd130b6

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

examples/TeensyRobustModuleLogger/TeensyRobustModuleLogger.ino

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ void setup()
7676
Log.level(module::LOOP, log_level_e::info);
7777
Log.echo(true); // log calls will also be printed over Serial
7878

79+
printf("Configured log levels are:\nSystem: %d, SETUP: %d, LOOP: %d\n",
80+
Log.level(), Log.level(module::SETUP), Log.level(module::LOOP));
81+
7982
// For demonstration purposes, we'll turn off auto-flush behavior
8083
// This will trigger overflow conditions in the loop() due to our flush
8184
// iteration count - we wait too long between flushes.

src/TeensyRobustModuleLogger.h

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ class TeensyRobustModuleLogger final : public LoggerBase
164164
return LoggerBase::level(l);
165165
}
166166

167+
/// Get the log level for ALL modules
168+
/// We need to forward this version to the base class version
169+
log_level_e level() const noexcept
170+
{
171+
return LoggerBase::level();
172+
}
173+
167174
/** Set the maximum log level (filtering) for the specified module
168175
*
169176
* @param module_id The ID for the corresponding module

src/TeensySDRotationalModuleLogger.h

+16
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ class TeensySDRotationalModuleLogger final : public LoggerBase
115115
return module_levels_[module_id];
116116
}
117117

118+
/// Set the log level for ALL modules
119+
/// We need to forward this version to the base class version
120+
/// to prevent us from calling level(module_id) when we try to set
121+
/// the global log level
122+
log_level_e level(log_level_e l) noexcept
123+
{
124+
return LoggerBase::level(l);
125+
}
126+
127+
/// Get the log level for ALL modules
128+
/// We need to forward this version to the base class version
129+
log_level_e level() const noexcept
130+
{
131+
return LoggerBase::level();
132+
}
133+
118134
/// The following overrides should be used to log with module IDs
119135

120136
template<typename... Args>

0 commit comments

Comments
 (0)