Skip to content
Snippets Groups Projects

make log() thread-safe by dropping the log level map

Closed Florian Fischer requested to merge aj46ezos/emper:thread_safe_log_config into master
1 file
+ 24
12
Compare changes
  • Side-by-side
  • Inline
+ 24
12
@@ -60,21 +60,33 @@ enum LogLevel {
@@ -60,21 +60,33 @@ enum LogLevel {
void worker_log(const std::string& prefix, const std::string& message);
void worker_log(const std::string& prefix, const std::string& message);
static const std::map<LogSubsystem, LogLevel> LOG_CONFIG = {
{ LogSubsystem::PS, ALL },
{ LogSubsystem::F, ALL },
{ LogSubsystem::C, ALL },
{ LogSubsystem::CM, ALL },
{ LogSubsystem::DISP, ALL },
{ LogSubsystem::SCHED, ALL },
{ LogSubsystem::RUNTI, ALL },
{ LogSubsystem::U_B_MPSC_Q, ALL },
};
template <LogSubsystem logSubsystem>
template <LogSubsystem logSubsystem>
class Logger {
class Logger {
private:
private:
 
static constexpr LogLevel getLevelFor(LogSubsystem system) {
 
switch (system) {
 
case LogSubsystem::PS:
 
return ALL;
 
case LogSubsystem::F:
 
return ALL;
 
case LogSubsystem::C:
 
return ALL;
 
case LogSubsystem::CM:
 
return ALL;
 
case LogSubsystem::DISP:
 
return ALL;
 
case LogSubsystem::SCHED:
 
return ALL;
 
case LogSubsystem::RUNTI:
 
return ALL;
 
case LogSubsystem::U_B_MPSC_Q:
 
return ALL;
 
default:
 
return ALL;
 
}
 
}
 
static constexpr char const * getTagFor(LogSubsystem system) {
static constexpr char const * getTagFor(LogSubsystem system) {
switch (system) {
switch (system) {
case LogSubsystem::PS:
case LogSubsystem::PS:
@@ -115,7 +127,7 @@ protected:
@@ -115,7 +127,7 @@ protected:
// Do not log any debug messages if NDEBUG is defined.
// Do not log any debug messages if NDEBUG is defined.
if (level >= Debug) return;
if (level >= Debug) return;
#endif
#endif
if (level > LOG_CONFIG.at(logSubsystem)) return;
if (level > getLevelFor(logSubsystem)) return;
std::string subSystemTag = getTagFor(logSubsystem);;
std::string subSystemTag = getTagFor(logSubsystem);;
Loading