diff --git a/include/vstd/CLoggerBase.h b/include/vstd/CLoggerBase.h index a263d78df..8e5dd2e3e 100644 --- a/include/vstd/CLoggerBase.h +++ b/include/vstd/CLoggerBase.h @@ -21,6 +21,26 @@ namespace ELogLevel WARN, ERROR }; + + inline std::string to_string(ELogLevel level) + { + switch (level) { + case NOT_SET: + return "not set"; + case TRACE: + return "trace"; + case DEBUG: + return "debug"; + case INFO: + return "info"; + case WARN: + return "warn"; + case ERROR: + return "error"; + default: + return std::string("invalid (") + std::to_string(level) + ")"; + } + } } namespace vstd diff --git a/lib/logging/CBasicLogConfigurator.cpp b/lib/logging/CBasicLogConfigurator.cpp index bd88fe6b2..d08b2e483 100644 --- a/lib/logging/CBasicLogConfigurator.cpp +++ b/lib/logging/CBasicLogConfigurator.cpp @@ -32,7 +32,9 @@ void CBasicLogConfigurator::configure() CLogger * logger = CLogger::getLogger(CLoggerDomain(name)); // Set log level - logger->setLevel(getLogLevel(loggerNode["level"].String())); + std::string level = loggerNode["level"].String(); + logger->setLevel(getLogLevel(level)); + logGlobal->debugStream() << "Set log level " << name << " => " << level; } } CLogger::getGlobalLogger()->clearTargets(); @@ -83,6 +85,11 @@ void CBasicLogConfigurator::configure() } logGlobal->infoStream() << "Initialized logging system based on settings successfully."; + for (auto& domain : CLogManager::get().getRegisteredDomains()) + { + logGlobal->infoStream() << "[log level] " << domain << " => " << + ELogLevel::to_string(CLogger::getLogger(CLoggerDomain(domain))->getLevel()); + } } ELogLevel::ELogLevel CBasicLogConfigurator::getLogLevel(const std::string & level) diff --git a/lib/logging/CLogger.cpp b/lib/logging/CLogger.cpp index 6578e8209..46175c04d 100644 --- a/lib/logging/CLogger.cpp +++ b/lib/logging/CLogger.cpp @@ -76,8 +76,14 @@ CLogger * CLogger::getLogger(const CLoggerDomain & domain) { logger = new CLogger(domain); if(domain.isGlobalDomain()) + { logger->setLevel(ELogLevel::TRACE); + } CLogManager::get().addLogger(logger); + if (logGlobal != nullptr) + { + logGlobal->debugStream() << "Created logger " << domain.getName(); + } } return logger; } @@ -198,6 +204,16 @@ CLogger * CLogManager::getLogger(const CLoggerDomain & domain) return nullptr; } +std::vector CLogManager::getRegisteredDomains() const +{ + std::vector domains; + for (auto& pair : loggers) + { + domains.push_back(pair.second->getDomain().getName()); + } + return std::move(domains); +} + CLogFormatter::CLogFormatter() : CLogFormatter("%m") { } CLogFormatter::CLogFormatter(const std::string & pattern) : pattern(pattern) diff --git a/lib/logging/CLogger.h b/lib/logging/CLogger.h index c7b1b5e4d..7bd573637 100644 --- a/lib/logging/CLogger.h +++ b/lib/logging/CLogger.h @@ -73,7 +73,7 @@ private: class DLL_LINKAGE CLogger: public vstd::CLoggerBase { public: - inline ELogLevel::ELogLevel getLevel() const; + ELogLevel::ELogLevel getLevel() const; void setLevel(ELogLevel::ELogLevel level); const CLoggerDomain & getDomain() const; @@ -159,10 +159,11 @@ public: void addLogger(CLogger * logger); CLogger * getLogger(const CLoggerDomain & domain); /// Returns a logger or nullptr if no one is registered for the given domain. + std::vector getRegisteredDomains() const; private: CLogManager(); - ~CLogManager(); + virtual ~CLogManager(); std::map loggers; mutable boost::mutex mx;