make log level settings avail in config file (#63)

This commit is contained in:
redPanther 2016-06-27 23:56:21 +02:00 committed by brindosch
parent 809ab82524
commit 03ac5689cf
6 changed files with 49 additions and 6 deletions

View File

@ -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

View File

@ -1,4 +1,9 @@
{ {
"logger" :
{
"level" : "warn"
},
"device" : "device" :
{ {
"name" : "DefaultHyperionConfig", "name" : "DefaultHyperionConfig",

View File

@ -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);

View File

@ -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),

View File

@ -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");
} }

View File

@ -75,5 +75,5 @@ private:
FramebufferWrapper* _fbGrabber; FramebufferWrapper* _fbGrabber;
OsxWrapper* _osxGrabber; OsxWrapper* _osxGrabber;
WebConfig* _webConfig; WebConfig* _webConfig;
Hyperion* _hyperion; Hyperion* _hyperion;
}; };