diff --git a/include/effectengine/EffectEngine.h b/include/effectengine/EffectEngine.h index 7acb1eea..163869d6 100644 --- a/include/effectengine/EffectEngine.h +++ b/include/effectengine/EffectEngine.h @@ -12,6 +12,7 @@ // Effect engine includes #include #include +#include // pre-declarioation class Effect; @@ -57,8 +58,10 @@ private: std::list _availableEffects; std::list _activeEffects; - + std::list _availableActiveEffects; - PyThreadState * _mainThreadState; + PyThreadState * _mainThreadState; + + Logger * _log; }; diff --git a/include/utils/Logger.h b/include/utils/Logger.h index 1282ebf4..518bf148 100644 --- a/include/utils/Logger.h +++ b/include/utils/Logger.h @@ -25,7 +25,7 @@ class Logger { public: - enum LogLevel { UNSET=0,DEBUG=1, INFO=2,WARNING=3,ERROR=4 }; + 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 void deleteInstance(std::string name=""); diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index 7f5d3534..c2c25419 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -10,6 +10,7 @@ // effect engin eincludes #include "Effect.h" +#include // Python method table PyMethodDef Effect::effectMethods[] = { @@ -112,7 +113,7 @@ void Effect::run() } else { - std::cerr << "EFFECTENGINE ERROR: Unable to open script file " << _script << std::endl; + Error(Logger::getInstance("EFFECTENGINE"), "Unable to open script file %s", _script.c_str()); } fclose(file); @@ -356,7 +357,7 @@ Effect * Effect::getEffect() { // something is wrong Py_XDECREF(module); - std::cerr << "EFFECTENGINE ERROR: Unable to retrieve the effect object from the Python runtime" << std::endl; + Error(Logger::getInstance("EFFECTENGINE"), "Unable to retrieve the effect object from the Python runtime"); return nullptr; } @@ -368,7 +369,7 @@ Effect * Effect::getEffect() { // something is wrong Py_XDECREF(effectCapsule); - std::cerr << "EFFECTENGINE ERROR: Unable to retrieve the effect object from the Python runtime" << std::endl; + Error(Logger::getInstance("EFFECTENGINE"), "Unable to retrieve the effect object from the Python runtime"); return nullptr; } diff --git a/libsrc/effectengine/Effect.h b/libsrc/effectengine/Effect.h index 0ef49315..7d8e7703 100644 --- a/libsrc/effectengine/Effect.h +++ b/libsrc/effectengine/Effect.h @@ -83,3 +83,4 @@ private: /// Buffer for colorData std::vector _colors; }; + diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 459fe239..0220dcfc 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -22,7 +22,8 @@ EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectCo _hyperion(hyperion), _availableEffects(), _activeEffects(), - _mainThreadState(nullptr) + _mainThreadState(nullptr), + _log(Logger::getInstance("EFFECTENGINE")) { qRegisterMetaType>("std::vector"); @@ -49,17 +50,17 @@ EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectCo efxCount++; } } - std::cerr << "EFFECTENGINE INFO: " << efxCount << " effects loaded from directory " << path << std::endl; + Info(_log, "%d effects loaded from directory %s", efxCount, path); } } if (_availableEffects.size() == 0) { - std::cerr << "EFFECTENGINE ERROR: no effects found, check your effect directories" << std::endl; + Error(_log, "no effects found, check your effect directories"); } // initialize the python interpreter - std::cout << "EFFECTENGINE INFO: Initializing Python interpreter" << std::endl; + Debug(_log,"Initializing Python interpreter"); Effect::registerHyperionExtensionModule(); Py_InitializeEx(0); PyEval_InitThreads(); // Create the GIL @@ -69,7 +70,7 @@ EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectCo EffectEngine::~EffectEngine() { // clean up the Python interpreter - std::cout << "EFFECTENGINE INFO: Cleaning up Python interpreter" << std::endl; + Debug(_log, "Cleaning up Python interpreter"); PyEval_RestoreThread(_mainThreadState); Py_Finalize(); } @@ -101,9 +102,10 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri std::string fileName = path + QDir::separator().toLatin1() + effectConfigFile; std::ifstream file(fileName.c_str()); + Logger * log = Logger::getInstance("EFFECTENGINE"); if (!file.is_open()) { - std::cerr << "EFFECTENGINE ERROR: Effect file '" << fileName << "' could not be loaded" << std::endl; + Error( log, "Effect file '%s' could not be loaded", fileName.c_str()); return false; } @@ -112,7 +114,7 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri Json::Value config; if (!jsonReader.parse(file, config, false)) { - std::cerr << "EFFECTENGINE ERROR: Error while reading effect '" << fileName << "': " << jsonReader.getFormattedErrorMessages() << std::endl; + Error( log, "Error while reading effect '%s': %s", fileName.c_str(), jsonReader.getFormattedErrorMessages().c_str()); return false; } @@ -126,7 +128,7 @@ bool EffectEngine::loadEffectDefinition(const std::string &path, const std::stri { const std::list & errors = schemaChecker.getMessages(); foreach (const std::string & error, errors) { - std::cerr << "EFFECTENGINE ERROR: Error while checking '" << fileName << "':" << error << std::endl; + Error( log, "Error while checking '%s':", fileName.c_str(), error.c_str()); } return false; } @@ -148,7 +150,7 @@ int EffectEngine::runEffect(const std::string &effectName, int priority, int tim int EffectEngine::runEffect(const std::string &effectName, const Json::Value &args, int priority, int timeout) { - std::cout << "EFFECTENGINE INFO: run effect " << effectName << " on channel " << priority << std::endl; + Info( _log, "run effect %s on channel %d", effectName.c_str(), priority); const EffectDefinition * effectDefinition = nullptr; for (const EffectDefinition & e : _availableEffects) @@ -162,7 +164,7 @@ int EffectEngine::runEffect(const std::string &effectName, const Json::Value &ar if (effectDefinition == nullptr) { // no such effect - std::cerr << "EFFECTENGINE ERROR: effect " << effectName << " not found" << std::endl; + Error(_log, "effect %s not found", effectName.c_str()); return -1; } @@ -213,7 +215,7 @@ void EffectEngine::effectFinished(Effect *effect) _hyperion->clear(effect->getPriority()); } - std::cout << "EFFECTENGINE INFO: effect finished" << std::endl; + Info( _log, "effect finished"); for (auto effectIt = _activeEffects.begin(); effectIt != _activeEffects.end(); ++effectIt) { if (*effectIt == effect) diff --git a/src/hyperiond/main.cpp b/src/hyperiond/main.cpp index d6e40984..4ca31bd5 100644 --- a/src/hyperiond/main.cpp +++ b/src/hyperiond/main.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) { // initialize main logger and set global log level Logger* log = Logger::getInstance("MAIN"); - Logger::setLogLevel(Logger::INFO); + Logger::setLogLevel(Logger::WARNING); // Initialising QCoreApplication QCoreApplication app(argc, argv); @@ -59,12 +59,40 @@ int main(int argc, char** argv) SwitchParameter<> & argVersion = parameters.add> (0x0, "version", "Show version information"); IntParameter & argParentPid = parameters.add (0x0, "parent", "pid of parent hyperiond"); + SwitchParameter<> & argSilent = parameters.add> (0x0, "silent", "do not print any outputs"); + SwitchParameter<> & argVerbose = parameters.add> (0x0, "verbose", "Increase verbosity"); + SwitchParameter<> & argDebug = parameters.add> (0x0, "debug", "Show debug messages"); SwitchParameter<> & argHelp = parameters.add> ('h', "help", "Show this help message and exit"); argParentPid.setDefault(0); optionParser.parse(argc, const_cast(argv)); const std::vector configFiles = optionParser.getFiles(); + int logLevelCheck = 0; + if (argSilent.isSet()) + { + Logger::setLogLevel(Logger::OFF); + logLevelCheck++; + } + + if (argVerbose.isSet()) + { + Logger::setLogLevel(Logger::INFO); + logLevelCheck++; + } + + if (argDebug.isSet()) + { + Logger::setLogLevel(Logger::DEBUG); + logLevelCheck++; + } + + if (logLevelCheck > 1) + { + Error(log, "aborting, because options --silent --verbose --debug can't used together"); + return 0; + } + // check if we need to display the usage. exit if we do. if (argHelp.isSet()) { @@ -109,7 +137,7 @@ int main(int argc, char** argv) Error(log, "No valid config found"); return 1; } - + HyperionDaemon* hyperiond = nullptr; try {