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:
parent
6f82dc3e15
commit
a4e550e3cf
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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<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(const std::string & pattern) : pattern(pattern)
|
||||
|
@ -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<std::string> getRegisteredDomains() const;
|
||||
|
||||
private:
|
||||
CLogManager();
|
||||
~CLogManager();
|
||||
virtual ~CLogManager();
|
||||
|
||||
std::map<std::string, CLogger *> loggers;
|
||||
mutable boost::mutex mx;
|
||||
|
Loading…
Reference in New Issue
Block a user