mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
make log level settings avail in config file (#63)
This commit is contained in:
parent
809ab82524
commit
03ac5689cf
@ -4,6 +4,12 @@
|
||||
|
||||
|
||||
{
|
||||
/// set log level: silent warn verbose debug
|
||||
"logger" :
|
||||
{
|
||||
"level" : "warn"
|
||||
},
|
||||
|
||||
/// Device configuration contains the following fields:
|
||||
/// * 'name' : The user friendly name of the device (only used for display purposes)
|
||||
/// * 'type' : The type of the device or leds (known types for now are
|
||||
|
@ -1,4 +1,9 @@
|
||||
{
|
||||
"logger" :
|
||||
{
|
||||
"level" : "warn"
|
||||
},
|
||||
|
||||
"device" :
|
||||
{
|
||||
"name" : "DefaultHyperionConfig",
|
||||
|
@ -30,9 +30,11 @@ public:
|
||||
static Logger* getInstance(std::string name="", LogLevel minLevel=Logger::INFO);
|
||||
static void deleteInstance(std::string name="");
|
||||
static void setLogLevel(LogLevel level,std::string name="");
|
||||
static LogLevel getLogLevel(std::string name="");
|
||||
|
||||
void Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...);
|
||||
void setMinLevel(LogLevel level) { _minLevel = level; };
|
||||
LogLevel getMinLevel() { return _minLevel; };
|
||||
|
||||
protected:
|
||||
Logger( std::string name="", LogLevel minLevel=INFO);
|
||||
|
@ -75,6 +75,16 @@ void Logger::setLogLevel(LogLevel level,std::string name)
|
||||
}
|
||||
}
|
||||
|
||||
Logger::LogLevel Logger::getLogLevel(std::string name)
|
||||
{
|
||||
if ( name.empty() )
|
||||
{
|
||||
return GLOBAL_MIN_LOG_LEVEL;
|
||||
}
|
||||
|
||||
Logger* log = Logger::getInstance(name);
|
||||
return log->getMinLevel();
|
||||
}
|
||||
|
||||
Logger::Logger ( std::string name, LogLevel minLevel ):
|
||||
_name(name),
|
||||
|
@ -42,6 +42,26 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent)
|
||||
{
|
||||
loadConfig(configFile);
|
||||
_hyperion = Hyperion::initInstance(_config, configFile);
|
||||
|
||||
if (Logger::getLogLevel() == Logger::WARNING)
|
||||
{
|
||||
if (_config.isMember("logger"))
|
||||
{
|
||||
const Json::Value & logConfig = _config["logger"];
|
||||
std::string level = logConfig.get("level", "warn").asString(); // silent warn verbose debug
|
||||
if (level == "silent") Logger::setLogLevel(Logger::OFF);
|
||||
else if (level == "warn") Logger::setLogLevel(Logger::WARNING);
|
||||
else if (level == "verbose") Logger::setLogLevel(Logger::INFO);
|
||||
else if (level == "debug") Logger::setLogLevel(Logger::DEBUG);
|
||||
else Error(Logger::getInstance("LOGGER"), "log level '%s' used in config is unknown. valid: silent warn verbose debug", level.c_str());
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningIf(_config.isMember("logger"), Logger::getInstance("LOGGER"), "Logger settings overriden by command line argument");
|
||||
}
|
||||
|
||||
Info(_log, "Hyperion started and initialised");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user