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:
|
/// Device configuration contains the following fields:
|
||||||
/// * 'name' : The user friendly name of the device (only used for display purposes)
|
/// * '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
|
/// * 'type' : The type of the device or leds (known types for now are
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
{
|
{
|
||||||
|
"logger" :
|
||||||
|
{
|
||||||
|
"level" : "warn"
|
||||||
|
},
|
||||||
|
|
||||||
"device" :
|
"device" :
|
||||||
{
|
{
|
||||||
"name" : "DefaultHyperionConfig",
|
"name" : "DefaultHyperionConfig",
|
||||||
|
@ -27,12 +27,14 @@ class Logger
|
|||||||
public:
|
public:
|
||||||
enum LogLevel { UNSET=0,DEBUG=1, INFO=2,WARNING=3,ERROR=4,OFF=5 };
|
enum LogLevel { UNSET=0,DEBUG=1, INFO=2,WARNING=3,ERROR=4,OFF=5 };
|
||||||
|
|
||||||
static Logger* getInstance(std::string name="", LogLevel minLevel=Logger::INFO);
|
static Logger* getInstance(std::string name="", LogLevel minLevel=Logger::INFO);
|
||||||
static void deleteInstance(std::string name="");
|
static void deleteInstance(std::string name="");
|
||||||
static void setLogLevel(LogLevel level,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 Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...);
|
||||||
void setMinLevel(LogLevel level) { _minLevel = level; };
|
void setMinLevel(LogLevel level) { _minLevel = level; };
|
||||||
|
LogLevel getMinLevel() { return _minLevel; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Logger( std::string name="", LogLevel minLevel=INFO);
|
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 ):
|
Logger::Logger ( std::string name, LogLevel minLevel ):
|
||||||
_name(name),
|
_name(name),
|
||||||
|
@ -42,6 +42,26 @@ HyperionDaemon::HyperionDaemon(std::string configFile, QObject *parent)
|
|||||||
{
|
{
|
||||||
loadConfig(configFile);
|
loadConfig(configFile);
|
||||||
_hyperion = Hyperion::initInstance(_config, 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");
|
Info(_log, "Hyperion started and initialised");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,5 +75,5 @@ private:
|
|||||||
FramebufferWrapper* _fbGrabber;
|
FramebufferWrapper* _fbGrabber;
|
||||||
OsxWrapper* _osxGrabber;
|
OsxWrapper* _osxGrabber;
|
||||||
WebConfig* _webConfig;
|
WebConfig* _webConfig;
|
||||||
Hyperion* _hyperion;
|
Hyperion* _hyperion;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user