1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Add log levels report

This commit is contained in:
Vadim Markovtsev 2016-10-02 20:21:20 +02:00
parent 6f82dc3e15
commit a4e550e3cf
4 changed files with 47 additions and 3 deletions

View File

@ -21,6 +21,26 @@ namespace ELogLevel
WARN, WARN,
ERROR 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 namespace vstd

View File

@ -32,7 +32,9 @@ void CBasicLogConfigurator::configure()
CLogger * logger = CLogger::getLogger(CLoggerDomain(name)); CLogger * logger = CLogger::getLogger(CLoggerDomain(name));
// Set log level // 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(); CLogger::getGlobalLogger()->clearTargets();
@ -83,6 +85,11 @@ void CBasicLogConfigurator::configure()
} }
logGlobal->infoStream() << "Initialized logging system based on settings successfully."; 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) ELogLevel::ELogLevel CBasicLogConfigurator::getLogLevel(const std::string & level)

View File

@ -76,8 +76,14 @@ CLogger * CLogger::getLogger(const CLoggerDomain & domain)
{ {
logger = new CLogger(domain); logger = new CLogger(domain);
if(domain.isGlobalDomain()) if(domain.isGlobalDomain())
{
logger->setLevel(ELogLevel::TRACE); logger->setLevel(ELogLevel::TRACE);
}
CLogManager::get().addLogger(logger); CLogManager::get().addLogger(logger);
if (logGlobal != nullptr)
{
logGlobal->debugStream() << "Created logger " << domain.getName();
}
} }
return logger; return logger;
} }
@ -198,6 +204,16 @@ CLogger * CLogManager::getLogger(const CLoggerDomain & domain)
return nullptr; return nullptr;
} }
std::vector<std::string> CLogManager::getRegisteredDomains() const
{
std::vector<std::string> domains;
for (auto& pair : loggers)
{
domains.push_back(pair.second->getDomain().getName());
}
return std::move(domains);
}
CLogFormatter::CLogFormatter() : CLogFormatter("%m") { } CLogFormatter::CLogFormatter() : CLogFormatter("%m") { }
CLogFormatter::CLogFormatter(const std::string & pattern) : pattern(pattern) CLogFormatter::CLogFormatter(const std::string & pattern) : pattern(pattern)

View File

@ -73,7 +73,7 @@ private:
class DLL_LINKAGE CLogger: public vstd::CLoggerBase class DLL_LINKAGE CLogger: public vstd::CLoggerBase
{ {
public: public:
inline ELogLevel::ELogLevel getLevel() const; ELogLevel::ELogLevel getLevel() const;
void setLevel(ELogLevel::ELogLevel level); void setLevel(ELogLevel::ELogLevel level);
const CLoggerDomain & getDomain() const; const CLoggerDomain & getDomain() const;
@ -159,10 +159,11 @@ public:
void addLogger(CLogger * logger); void addLogger(CLogger * logger);
CLogger * getLogger(const CLoggerDomain & domain); /// Returns a logger or nullptr if no one is registered for the given domain. CLogger * getLogger(const CLoggerDomain & domain); /// Returns a logger or nullptr if no one is registered for the given domain.
std::vector<std::string> getRegisteredDomains() const;
private: private:
CLogManager(); CLogManager();
~CLogManager(); virtual ~CLogManager();
std::map<std::string, CLogger *> loggers; std::map<std::string, CLogger *> loggers;
mutable boost::mutex mx; mutable boost::mutex mx;