diff --git a/emper/Debug.hpp b/emper/Debug.hpp index b02d89c07eed87eca25f1812f85c2c92bc746070..3c077ffe66bbf69b6677ec7dcef07439072af0a5 100644 --- a/emper/Debug.hpp +++ b/emper/Debug.hpp @@ -5,6 +5,7 @@ #include <iostream> // IWYU pragma: keep #include <sstream> // IWYU pragma: keep #include <string> // for string, operator<< +#include <string_view> #include "emper-config.h" // IWYU pragma: keep @@ -67,7 +68,6 @@ enum class LogSubsystem { }; enum LogLevel { - OFF, Error, Warning, Info, @@ -78,11 +78,6 @@ enum LogLevel { ALL, }; -// global log level -namespace emper { -extern enum LogLevel log_level; -} - void emper_add_timestamp_to(std::ostringstream& logMessage); void emper_log(const std::string& prefix, const std::string& message); @@ -106,7 +101,7 @@ class Logger { } } - static constexpr auto getTagFor(LogSubsystem system) -> char const* { + static constexpr auto getTagFor(LogSubsystem system) -> std::string_view { switch (system) { case LogSubsystem::PS: return "PS "; @@ -142,31 +137,29 @@ class Logger { } protected: - inline void log(LogLevel level, const std::string& string) const { -#ifdef EMPER_LOG_OFF - return; -#endif + template <enum LogLevel level> + inline void log(const std::string& string) const { // check global level - if (level > emper::log_level) return; + if constexpr (level > EMPER_LOG_LEVEL) return; // check subsystem level - if (level > getLevelFor(logSubsystem)) return; + if constexpr (level > getLevelFor(logSubsystem)) return; - std::string subSystemTag = getTagFor(logSubsystem); + constexpr std::string_view subSystemTag = getTagFor(logSubsystem); std::ostringstream sst; sst << subSystemTag; - if (shouldPrefixThis(logSubsystem)) { + if constexpr (shouldPrefixThis(logSubsystem)) { sst << " " << this; } emper_log(sst.str(), string); } - inline void logE(const std::string& string) const { log(Error, string); } + inline void logE(const std::string& string) const { log<Error>(string); } - inline void logI(const std::string& string) const { log(Info, string); } + inline void logI(const std::string& string) const { log<Info>(string); } - inline void logD(const std::string& string) const { log(Debug, string); } + inline void logD(const std::string& string) const { log<Debug>(string); } - inline void logDD(const std::string& string) const { log(FineDebug, string); } + inline void logDD(const std::string& string) const { log<FineDebug>(string); } }; diff --git a/emper/Semaphore.cpp b/emper/Semaphore.cpp index 0de3b07a197c86003c09f74a17a0928c8fb7c998..19941ad4e057ef24b605d56629cf2581c5dfcbe7 100644 --- a/emper/Semaphore.cpp +++ b/emper/Semaphore.cpp @@ -4,7 +4,7 @@ #include <iostream> // for operator<<, basic_ostream, basic_o... -#include "Debug.hpp" // for emper +#include "Emper.hpp" // for emper using namespace emper; diff --git a/meson.build b/meson.build index 69f961dad178bd8fbc77320afe1058e4d3b64a52..9a6bca81395dbc6709f34424cceb7d1d02aca18a 100644 --- a/meson.build +++ b/meson.build @@ -59,10 +59,7 @@ conf_data.set('EMPER_DEFAULT_SCHEDULING_STRATEGY_' + default_scheduling_strategy log_level = get_option('log_level') if log_level == 'automatic' # output only error messages in release builds - log_level = get_option('buildtype') == 'release' ? 'Error' : 'ALL' -# turn logging of during compilation -elif log_level == 'OFF' - conf_data.set('EMPER_LOG_OFF', true) + log_level = get_option('debug') ? 'ALL' : 'Info' endif conf_data.set('EMPER_LOG_LEVEL', log_level) conf_data.set('EMPER_LOG_TIMESTAMP', get_option('log_timestamp')) diff --git a/meson_options.txt b/meson_options.txt index ac769500be89ab35a157e2a6a7bf662b1f2cb100..06bd0206e6218ed75a6d44f669ca504ea368ef4e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,7 +7,7 @@ option( option( 'log_level', type: 'combo', - choices: ['automatic', 'OFF', 'Error', 'Warning', 'Info', 'Debug', 'FineDebug', 'FinerDebug', 'FinestDebug', 'ALL'], + choices: ['automatic', 'Error', 'Warning', 'Info', 'Debug', 'FineDebug', 'FinerDebug', 'FinestDebug', 'ALL'], value: 'automatic', ) option(