diff --git a/assets/webconfig/js/content_logging.js b/assets/webconfig/js/content_logging.js index ce95e603..0d5ffa02 100644 --- a/assets/webconfig/js/content_logging.js +++ b/assets/webconfig/js/content_logging.js @@ -121,8 +121,8 @@ $(document).ready(function () { if (messages.length != 0) { for (var idx = 0; idx < messages.length; idx++) { - var app_name = messages[idx].appName; var logger_name = messages[idx].loggerName; + var logger_subname = messages[idx].loggerSubName; var function_ = messages[idx].function; var line = messages[idx].line; var file_name = messages[idx].fileName; @@ -136,7 +136,18 @@ $(document).ready(function () { } var date = new Date(parseInt(utime)); - var newLogLine = date.toISOString() + " [" + app_name + " " + logger_name + "] (" + level_string + ") " + debug + msg; + var subComponent = ""; + if (window.serverInfo.instance.length > 1) { + if (logger_subname.startsWith("I")) { + var instanceNum = logger_subname.substring(1); + if (window.serverInfo.instance[instanceNum]) { + subComponent = window.serverInfo.instance[instanceNum].friendly_name; + } else { + subComponent = instanceNum; + } + } + } + var newLogLine = date.toISOString() + " [" + logger_name + (subComponent ? "|" + subComponent : "") + "] (" + level_string + ") " + debug + msg; $("#logmessages").append("" + newLogLine + "\n"); } diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index b4daaac0..27e5e5ff 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -256,7 +256,7 @@ public slots: /// @brief Get a pointer to the priorityMuxer instance /// @return PriorityMuxer instance pointer /// - PriorityMuxer* getMuxerInstance() { return &_muxer; } + PriorityMuxer* getMuxerInstance() { return _muxer; } /// /// @brief enable/disable automatic/priorized source selection @@ -340,7 +340,7 @@ public slots: /// @brief Get the component Register /// return Component register pointer /// - ComponentRegister & getComponentRegister() { return _componentRegister; } + ComponentRegister* getComponentRegister() { return _componentRegister; } /// /// @brief Called from components to update their current state. DO NOT CALL FROM USERS @@ -511,7 +511,7 @@ private: SettingsManager* _settingsManager; /// Register that holds component states - ComponentRegister _componentRegister; + ComponentRegister* _componentRegister; /// The specifiation of the led frame construction and picture integration LedString _ledString; @@ -522,7 +522,7 @@ private: std::vector _ledStringColorOrder; /// The priority muxer - PriorityMuxer _muxer; + PriorityMuxer* _muxer; /// The adjustment from raw colors to led colors MultiColorAdjustment * _raw2ledAdjustment; diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index 576013ab..76b885a9 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -152,6 +152,13 @@ public: /// static void printLedValues(const std::vector& ledValues); + /// + /// @brief Set the common logger for LED-devices. + /// + /// @param[in] log The logger to be used + /// + void setLogger(Logger* log) { _log = log; } + public slots: /// diff --git a/include/utils/Logger.h b/include/utils/Logger.h index 3aa3c1c9..74c36954 100644 --- a/include/utils/Logger.h +++ b/include/utils/Logger.h @@ -54,8 +54,8 @@ public: struct T_LOG_MESSAGE { - QString appName; QString loggerName; + QString loggerSubName; QString function; unsigned int line; QString fileName; @@ -65,22 +65,22 @@ public: QString levelString; }; - static Logger* getInstance(const QString & name = "", LogLevel minLevel=Logger::INFO); - static void deleteInstance(const QString & name = ""); - static void setLogLevel(LogLevel level, const QString & name = ""); - static LogLevel getLogLevel(const QString & name = ""); + static Logger* getInstance(const QString & name = "", const QString & subName = "__", LogLevel minLevel=Logger::INFO); + static void deleteInstance(const QString & name = "", const QString & subName = "__"); + static void setLogLevel(LogLevel level, const QString & name = "", const QString & subName = "__"); + static LogLevel getLogLevel(const QString & name = "", const QString & subName = "__"); void Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...); void setMinLevel(LogLevel level) { _minLevel = static_cast(level); } LogLevel getMinLevel() const { return static_cast(int(_minLevel)); } QString getName() const { return _name; } - QString getAppName() const { return _appname; } + QString getSubName() const { return _subname; } signals: void newLogMessage(Logger::T_LOG_MESSAGE); protected: - Logger(const QString & name="", LogLevel minLevel = INFO); + Logger(const QString & name="", const QString & subName = "__", LogLevel minLevel = INFO); ~Logger() override; private: @@ -95,12 +95,12 @@ private: static QAtomicInteger GLOBAL_MIN_LOG_LEVEL; const QString _name; - const QString _appname; + const QString _subname; const bool _syslogEnabled; const unsigned _loggerId; /* Only non-const member, hence the atomic */ - QAtomicInteger _minLevel; + QAtomicInteger _minLevel; }; class LoggerManager : public QObject diff --git a/include/utils/hyperion.h b/include/utils/hyperion.h index d1803e0d..885ac36b 100644 --- a/include/utils/hyperion.h +++ b/include/utils/hyperion.h @@ -44,12 +44,12 @@ namespace hyperion { } }; hyperion->setColor(PriorityMuxer::FG_PRIORITY, fg_color, fg_duration_ms); - Info(Logger::getInstance("HYPERION"),"Initial foreground color set (%d %d %d)",fg_color.at(0).red,fg_color.at(0).green,fg_color.at(0).blue); + Info(Logger::getInstance("HYPERION","I"+QString::number(hyperion->getInstanceIndex())),"Initial foreground color set (%d %d %d)",fg_color.at(0).red,fg_color.at(0).green,fg_color.at(0).blue); } else { int result = hyperion->setEffect(fgEffectConfig, PriorityMuxer::FG_PRIORITY, fg_duration_ms); - Info(Logger::getInstance("HYPERION"),"Initial foreground effect '%s' %s", QSTRING_CSTR(fgEffectConfig), ((result == 0) ? "started" : "failed")); + Info(Logger::getInstance("HYPERION","I"+QString::number(hyperion->getInstanceIndex())),"Initial foreground effect '%s' %s", QSTRING_CSTR(fgEffectConfig), ((result == 0) ? "started" : "failed")); } } #undef FGCONFIG_ARRAY diff --git a/libsrc/api/API.cpp b/libsrc/api/API.cpp index 12d3f23e..c2a0acdd 100644 --- a/libsrc/api/API.cpp +++ b/libsrc/api/API.cpp @@ -72,6 +72,8 @@ API::API(Logger *log, bool localConnection, QObject *parent) void API::init() { + assert(_hyperion); + bool apiAuthRequired = _authManager->isAuthRequired(); // For security we block external connections if default PW is set diff --git a/libsrc/api/JsonAPI.cpp b/libsrc/api/JsonAPI.cpp index cbe9d6bd..e6513767 100644 --- a/libsrc/api/JsonAPI.cpp +++ b/libsrc/api/JsonAPI.cpp @@ -617,7 +617,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString // get available components QJsonArray component; - std::map components = _hyperion->getComponentRegister().getRegister(); + std::map components = _hyperion->getComponentRegister()->getRegister(); for (auto comp : components) { QJsonObject item; @@ -1154,7 +1154,9 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co { _streaming_logging_reply["command"] = command + "-update"; connect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage); - Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); // needed to trigger log sending + + emit incommingLogMessage (Logger::T_LOG_MESSAGE{}); // needed to trigger log sending + Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); } } else if (subcommand == "stop") @@ -1783,22 +1785,26 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg) const QList *logBuffer = LoggerManager::getInstance()->getLogMessageBuffer(); for (int i = 0; i < logBuffer->length(); i++) { - message["appName"] = logBuffer->at(i).appName; - message["loggerName"] = logBuffer->at(i).loggerName; - message["function"] = logBuffer->at(i).function; - message["line"] = QString::number(logBuffer->at(i).line); - message["fileName"] = logBuffer->at(i).fileName; - message["message"] = logBuffer->at(i).message; - message["levelString"] = logBuffer->at(i).levelString; - message["utime"] = QString::number(logBuffer->at(i).utime); + //Only present records of the current log-level + if ( logBuffer->at(i).level >= _log->getLogLevel()) + { + message["loggerName"] = logBuffer->at(i).loggerName; + message["loggerSubName"] = logBuffer->at(i).loggerSubName; + message["function"] = logBuffer->at(i).function; + message["line"] = QString::number(logBuffer->at(i).line); + message["fileName"] = logBuffer->at(i).fileName; + message["message"] = logBuffer->at(i).message; + message["levelString"] = logBuffer->at(i).levelString; + message["utime"] = QString::number(logBuffer->at(i).utime); - messageArray.append(message); + messageArray.append(message); + } } } else { - message["appName"] = msg.appName; message["loggerName"] = msg.loggerName; + message["loggerSubName"] = msg.loggerSubName; message["function"] = msg.function; message["line"] = QString::number(msg.line); message["fileName"] = msg.fileName; diff --git a/libsrc/api/JsonCB.cpp b/libsrc/api/JsonCB.cpp index 4dafd497..fce3fedd 100644 --- a/libsrc/api/JsonCB.cpp +++ b/libsrc/api/JsonCB.cpp @@ -156,6 +156,7 @@ void JsonCB::resetSubscriptions() void JsonCB::setSubscriptionsTo(Hyperion* hyperion) { + assert(hyperion); //std::cout << "JsonCB::setSubscriptions for instance [" << static_cast(hyperion->getInstanceIndex()) << "] " << std::endl; // get current subs @@ -166,7 +167,7 @@ void JsonCB::setSubscriptionsTo(Hyperion* hyperion) // update pointer _hyperion = hyperion; - _componentRegister = &_hyperion->getComponentRegister(); + _componentRegister = _hyperion->getComponentRegister(); _prioMuxer = _hyperion->getMuxerInstance(); // re-apply subs diff --git a/libsrc/blackborder/BlackBorderProcessor.cpp b/libsrc/blackborder/BlackBorderProcessor.cpp index 570cd9d2..eadc56c2 100644 --- a/libsrc/blackborder/BlackBorderProcessor.cpp +++ b/libsrc/blackborder/BlackBorderProcessor.cpp @@ -69,7 +69,7 @@ void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJson _detector = new BlackBorderDetector(newThreshold); } - Debug(Logger::getInstance("BLACKBORDER"), "Set mode to: %s", QSTRING_CSTR(_detectionMode)); + Debug(Logger::getInstance("BLACKBORDER", "I"+QString::number(_hyperion->getInstanceIndex())), "Set mode to: %s", QSTRING_CSTR(_detectionMode)); // eval the comp state handleCompStateChangeRequest(hyperion::COMP_BLACKBORDER, obj["enable"].toBool(true)); diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 42386512..4e982dad 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -19,9 +19,12 @@ EffectEngine::EffectEngine(Hyperion * hyperion) : _hyperion(hyperion) - , _log(Logger::getInstance("EFFECTENGINE")) + , _log(nullptr) , _effectFileHandler(EffectFileHandler::getInstance()) { + QString subComponent = hyperion->property("instance").toString(); + _log= Logger::getInstance("EFFECTENGINE", subComponent); + Q_INIT_RESOURCE(EffectEngine); qRegisterMetaType("hyperion::Components"); diff --git a/libsrc/forwarder/MessageForwarder.cpp b/libsrc/forwarder/MessageForwarder.cpp index 899f6e28..9abddeea 100644 --- a/libsrc/forwarder/MessageForwarder.cpp +++ b/libsrc/forwarder/MessageForwarder.cpp @@ -21,11 +21,14 @@ MessageForwarder::MessageForwarder(Hyperion* hyperion) : _hyperion(hyperion) - , _log(Logger::getInstance("NETFORWARDER")) + , _log(nullptr) , _muxer(_hyperion->getMuxerInstance()) , _forwarder_enabled(true) , _priority(140) { + QString subComponent = hyperion->property("instance").toString(); + _log= Logger::getInstance("NETFORWARDER", subComponent); + // get settings updates connect(_hyperion, &Hyperion::settingsChanged, this, &MessageForwarder::handleSettingsUpdate); diff --git a/libsrc/hyperion/ComponentRegister.cpp b/libsrc/hyperion/ComponentRegister.cpp index c5e80ffa..0053c6c6 100644 --- a/libsrc/hyperion/ComponentRegister.cpp +++ b/libsrc/hyperion/ComponentRegister.cpp @@ -9,8 +9,11 @@ using namespace hyperion; ComponentRegister::ComponentRegister(Hyperion* hyperion) : _hyperion(hyperion) - , _log(Logger::getInstance("COMPONENTREG")) + , _log(nullptr) { + QString subComponent = hyperion->property("instance").toString(); + _log= Logger::getInstance("COMPONENTREG", subComponent); + // init all comps to false QVector vect; vect << COMP_ALL << COMP_SMOOTHING << COMP_LEDDEVICE; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index 1bcdbb1f..0c1b7c84 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -49,10 +49,10 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode) : QObject() , _instIndex(instance) , _settingsManager(new SettingsManager(instance, this, readonlyMode)) - , _componentRegister(this) + , _componentRegister(nullptr) , _ledString(hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object()))) - , _imageProcessor(new ImageProcessor(_ledString, this)) - , _muxer(static_cast(_ledString.leds().size()), this) + , _imageProcessor(nullptr) + , _muxer(nullptr) , _raw2ledAdjustment(hyperion::createLedColorsAdjustment(static_cast(_ledString.leds().size()), getSetting(settings::COLOR).object())) , _ledDeviceWrapper(nullptr) , _deviceSmooth(nullptr) @@ -60,7 +60,7 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode) #if defined(ENABLE_FORWARDER) , _messageForwarder(nullptr) #endif - , _log(Logger::getInstance("HYPERION")) + , _log(nullptr) , _hwLedCount() , _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array())) , _BGEffectHandler(nullptr) @@ -71,7 +71,14 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode) #endif , _readOnlyMode(readonlyMode) { + QString subComponent = "I"+QString::number(instance); + this->setProperty("instance", (QString) subComponent); + _log= Logger::getInstance("HYPERION", subComponent); + + _componentRegister = new ComponentRegister(this); + _imageProcessor = new ImageProcessor(_ledString, this); + _muxer = new PriorityMuxer(static_cast(_ledString.leds().size()), this); } Hyperion::~Hyperion() @@ -102,9 +109,9 @@ void Hyperion::start() } // connect Hyperion::update with Muxer visible priority changes as muxer updates independent - connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::update); - connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability); - connect(&_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged); + connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::update); + connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability); + connect(_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged); // listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions // connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState); @@ -199,6 +206,10 @@ void Hyperion::freeObjects() delete _settingsManager; delete _ledDeviceWrapper; + + delete _imageProcessor; + delete _muxer; + delete _componentRegister; } void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& config) @@ -228,7 +239,7 @@ void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& co // ledstring, img processor, muxer, ledGridSize (effect-engine image based effects), _ledBuffer and ByteOrder of ledstring _ledString = hyperion::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object())); _imageProcessor->setLedString(_ledString); - _muxer.updateLedColorsLength(static_cast(_ledString.leds().size())); + _muxer->updateLedColorsLength(static_cast(_ledString.leds().size())); _ledGridSize = hyperion::getLedLayoutGridSize(leds); std::vector color(_ledString.leds().size(), ColorRgb{0,0,0}); @@ -322,42 +333,42 @@ int Hyperion::getLedCount() const void Hyperion::setSourceAutoSelect(bool state) { - _muxer.setSourceAutoSelectEnabled(state); + _muxer->setSourceAutoSelectEnabled(state); } bool Hyperion::setVisiblePriority(int priority) { - return _muxer.setPriority(priority); + return _muxer->setPriority(priority); } bool Hyperion::sourceAutoSelectEnabled() const { - return _muxer.isSourceAutoSelectEnabled(); + return _muxer->isSourceAutoSelectEnabled(); } void Hyperion::setNewComponentState(hyperion::Components component, bool state) { - _componentRegister.setNewComponentState(component, state); + _componentRegister->setNewComponentState(component, state); } std::map Hyperion::getAllComponents() const { - return _componentRegister.getRegister(); + return _componentRegister->getRegister(); } int Hyperion::isComponentEnabled(hyperion::Components comp) const { - return _componentRegister.isComponentEnabled(comp); + return _componentRegister->isComponentEnabled(comp); } void Hyperion::registerInput(int priority, hyperion::Components component, const QString& origin, const QString& owner, unsigned smooth_cfg) { - _muxer.registerInput(priority, component, origin, owner, smooth_cfg); + _muxer->registerInput(priority, component, origin, owner, smooth_cfg); } bool Hyperion::setInput(int priority, const std::vector& ledColors, int timeout_ms, bool clearEffect) { - if(_muxer.setInput(priority, ledColors, timeout_ms)) + if(_muxer->setInput(priority, ledColors, timeout_ms)) { // clear effect if this call does not come from an effect if(clearEffect) @@ -366,7 +377,7 @@ bool Hyperion::setInput(int priority, const std::vector& ledColors, in } // if this priority is visible, update immediately - if(priority == _muxer.getCurrentPriority()) + if(priority == _muxer->getCurrentPriority()) { update(); } @@ -378,13 +389,13 @@ bool Hyperion::setInput(int priority, const std::vector& ledColors, in bool Hyperion::setInputImage(int priority, const Image& image, int64_t timeout_ms, bool clearEffect) { - if (!_muxer.hasPriority(priority)) + if (!_muxer->hasPriority(priority)) { emit GlobalSignals::getInstance()->globalRegRequired(priority); return false; } - if(_muxer.setInputImage(priority, image, timeout_ms)) + if(_muxer->setInputImage(priority, image, timeout_ms)) { // clear effect if this call does not come from an effect if(clearEffect) @@ -393,7 +404,7 @@ bool Hyperion::setInputImage(int priority, const Image& image, int64_t } // if this priority is visible, update immediately - if(priority == _muxer.getCurrentPriority()) + if(priority == _muxer->getCurrentPriority()) { update(); } @@ -405,7 +416,7 @@ bool Hyperion::setInputImage(int priority, const Image& image, int64_t bool Hyperion::setInputInactive(quint8 priority) { - return _muxer.setInputInactive(priority); + return _muxer->setInputInactive(priority); } void Hyperion::setColor(int priority, const std::vector &ledColors, int timeout_ms, const QString &origin, bool clearEffects) @@ -465,7 +476,7 @@ bool Hyperion::clear(int priority, bool forceClearAll) bool isCleared = false; if (priority < 0) { - _muxer.clearAll(forceClearAll); + _muxer->clearAll(forceClearAll); // send clearall signal to the effect engine _effectEngine->allChannelsCleared(); @@ -477,7 +488,7 @@ bool Hyperion::clear(int priority, bool forceClearAll) // (outside the check so the effect gets cleared even when the effect is not sending colors) _effectEngine->channelCleared(priority); - if (_muxer.clearInput(priority)) + if (_muxer->clearInput(priority)) { isCleared = true; } @@ -487,7 +498,7 @@ bool Hyperion::clear(int priority, bool forceClearAll) int Hyperion::getCurrentPriority() const { - return _muxer.getCurrentPriority(); + return _muxer->getCurrentPriority(); } bool Hyperion::isCurrentPriority(int priority) const @@ -497,12 +508,12 @@ bool Hyperion::isCurrentPriority(int priority) const QList Hyperion::getActivePriorities() const { - return _muxer.getPriorities(); + return _muxer->getPriorities(); } Hyperion::InputInfo Hyperion::getPriorityInfo(int priority) const { - return _muxer.getInputInfo(priority); + return _muxer->getInputInfo(priority); } QString Hyperion::saveEffect(const QJsonObject& obj) @@ -582,7 +593,7 @@ void Hyperion::handleVisibleComponentChanged(hyperion::Components comp) } void Hyperion::handleSourceAvailability(const quint8& priority) -{ int previousPriority = _muxer.getPreviousPriority(); +{ int previousPriority = _muxer->getPreviousPriority(); Debug(_log,"priority[%d], previousPriority[%d]", priority, previousPriority); if ( priority == PriorityMuxer::LOWEST_PRIORITY) @@ -605,8 +616,8 @@ void Hyperion::handleSourceAvailability(const quint8& priority) void Hyperion::update() { // Obtain the current priority channel - int priority = _muxer.getCurrentPriority(); - const PriorityMuxer::InputInfo priorityInfo = _muxer.getInputInfo(priority); + int priority = _muxer->getCurrentPriority(); + const PriorityMuxer::InputInfo priorityInfo = _muxer->getInputInfo(priority); // copy image & process OR copy ledColors from muxer Image image = priorityInfo.image; diff --git a/libsrc/hyperion/HyperionIManager.cpp b/libsrc/hyperion/HyperionIManager.cpp index f1080156..ec1ffe65 100644 --- a/libsrc/hyperion/HyperionIManager.cpp +++ b/libsrc/hyperion/HyperionIManager.cpp @@ -11,7 +11,7 @@ HyperionIManager* HyperionIManager::HIMinstance; HyperionIManager::HyperionIManager(const QString& rootPath, QObject* parent, bool readonlyMode) : QObject(parent) - , _log(Logger::getInstance("HYPERION")) + , _log(Logger::getInstance("HYPERION-INSTMGR")) , _instanceTable( new InstanceTable(rootPath, this, readonlyMode) ) , _rootPath( rootPath ) , _readonlyMode(readonlyMode) diff --git a/libsrc/hyperion/ImageProcessor.cpp b/libsrc/hyperion/ImageProcessor.cpp index e442f086..f527a3a9 100644 --- a/libsrc/hyperion/ImageProcessor.cpp +++ b/libsrc/hyperion/ImageProcessor.cpp @@ -28,7 +28,7 @@ QString ImageProcessor::mappingTypeToStr(int mappingType) ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion) : QObject(hyperion) - , _log(Logger::getInstance("IMAGETOLED")) + , _log(nullptr) , _ledString(ledString) , _borderProcessor(new BlackBorderProcessor(hyperion, this)) , _imageToLeds(nullptr) @@ -37,6 +37,9 @@ ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion) , _hardMappingType(0) , _hyperion(hyperion) { + QString subComponent = hyperion->property("instance").toString(); + _log= Logger::getInstance("IMAGETOLED", subComponent); + // init handleSettingsUpdate(settings::COLOR, _hyperion->getSetting(settings::COLOR)); // listen for changes in color - ledmapping diff --git a/libsrc/hyperion/LinearColorSmoothing.cpp b/libsrc/hyperion/LinearColorSmoothing.cpp index afb0f47d..5cfa20f8 100644 --- a/libsrc/hyperion/LinearColorSmoothing.cpp +++ b/libsrc/hyperion/LinearColorSmoothing.cpp @@ -50,7 +50,7 @@ const unsigned DEFAUL_OUTPUTDEPLAY = 0; // outputdelay in ms LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion) : QObject(hyperion) - , _log(Logger::getInstance("SMOOTHING")) + , _log(nullptr) , _hyperion(hyperion) , _updateInterval(DEFAUL_UPDATEINTERVALL.count()) , _settlingTime(DEFAUL_SETTLINGTIME) @@ -62,6 +62,9 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion , _enabled(false) , tempValues(std::vector(0, 0L)) { + QString subComponent = hyperion->property("instance").toString(); + _log= Logger::getInstance("SMOOTHING", subComponent); + // init cfg 0 (default) addConfig(DEFAUL_SETTLINGTIME, DEFAUL_UPDATEFREQUENCY, DEFAUL_OUTPUTDEPLAY); handleSettingsUpdate(settings::SMOOTHING, config); diff --git a/libsrc/hyperion/PriorityMuxer.cpp b/libsrc/hyperion/PriorityMuxer.cpp index 3c277341..39cb58e0 100644 --- a/libsrc/hyperion/PriorityMuxer.cpp +++ b/libsrc/hyperion/PriorityMuxer.cpp @@ -20,7 +20,7 @@ const int PriorityMuxer::TIMEOUT_NOT_ACTIVE_PRIO = -100; PriorityMuxer::PriorityMuxer(int ledCount, QObject * parent) : QObject(parent) - , _log(Logger::getInstance("HYPERION")) + , _log(nullptr) , _currentPriority(PriorityMuxer::LOWEST_PRIORITY) , _previousPriority(_currentPriority) , _manualSelectedPriority(MANUAL_SELECTED_PRIORITY) @@ -32,6 +32,9 @@ PriorityMuxer::PriorityMuxer(int ledCount, QObject * parent) , _timer(new QTimer(this)) , _blockTimer(new QTimer(this)) { + QString subComponent = parent->property("instance").toString(); + _log= Logger::getInstance("MUXER", subComponent); + // init lowest priority info _lowestPriorityInfo.priority = PriorityMuxer::LOWEST_PRIORITY; _lowestPriorityInfo.timeoutTime_ms = -1; diff --git a/libsrc/hyperion/SettingsManager.cpp b/libsrc/hyperion/SettingsManager.cpp index 72f8ea0e..b045100d 100644 --- a/libsrc/hyperion/SettingsManager.cpp +++ b/libsrc/hyperion/SettingsManager.cpp @@ -28,7 +28,7 @@ QJsonObject SettingsManager::schemaJson; SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonlyMode) : QObject(parent) - , _log(Logger::getInstance("SETTINGSMGR")) + , _log(Logger::getInstance("SETTINGSMGR", "I"+QString::number(instance))) , _instance(instance) , _sTable(new SettingsTable(instance, this)) , _configVersion(DEFAULT_VERSION) @@ -628,6 +628,8 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) { newJsonConfig["port"] = 19444; } + newJsonConfig["name"] = host; + json.append(newJsonConfig); migrated = true; } @@ -636,13 +638,10 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) if (!json.isEmpty()) { - newForwarderConfig["json"] = json; - } - else - { - newForwarderConfig.remove("json"); - migrated = true; + newForwarderConfig["jsonapi"] = json; } + newForwarderConfig.remove("json"); + migrated = true; } QJsonArray flatbuffer; @@ -672,6 +671,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) { newFlattbufferConfig["port"] = 19400; } + newFlattbufferConfig["name"] = host; flatbuffer.append(newFlattbufferConfig); migrated = true; @@ -680,13 +680,10 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config) if (!flatbuffer.isEmpty()) { - newForwarderConfig["flat"] = flatbuffer; - } - else - { - newForwarderConfig.remove("flat"); - migrated = true; + newForwarderConfig["flatbuffer"] = flatbuffer; } + newForwarderConfig.remove("flat"); + migrated = true; } } diff --git a/libsrc/leddevice/LedDeviceWrapper.cpp b/libsrc/leddevice/LedDeviceWrapper.cpp index 7e45b7b8..0f976316 100644 --- a/libsrc/leddevice/LedDeviceWrapper.cpp +++ b/libsrc/leddevice/LedDeviceWrapper.cpp @@ -56,6 +56,10 @@ void LedDeviceWrapper::createLedDevice(const QJsonObject& config) QThread* thread = new QThread(this); thread->setObjectName("LedDeviceThread"); _ledDevice = LedDeviceFactory::construct(config); + + QString subComponent = parent()->property("instance").toString(); + _ledDevice->setLogger(Logger::getInstance("LEDDEVICE", subComponent)); + _ledDevice->moveToThread(thread); // setup thread management connect(thread, &QThread::started, _ledDevice, &LedDevice::start); @@ -92,13 +96,13 @@ QJsonObject LedDeviceWrapper::getLedDeviceSchemas() QString devName = item.remove("schema-"); QString data; - if(!FileUtils::readFile(schemaPath, data, Logger::getInstance("LedDevice"))) + if(!FileUtils::readFile(schemaPath, data, Logger::getInstance("LEDDEVICE"))) { throw std::runtime_error("ERROR: Schema not found: " + item.toStdString()); } QJsonObject schema; - if(!JsonUtils::parse(schemaPath, data, schema, Logger::getInstance("LedDevice"))) + if(!JsonUtils::parse(schemaPath, data, schema, Logger::getInstance("LEDDEVICE"))) { throw std::runtime_error("ERROR: JSON schema wrong of file: " + item.toStdString()); } diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 2fe7f123..0fcae0cc 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -28,7 +28,7 @@ QAtomicInteger Logger::GLOBAL_MIN_LOG_LEVEL { static_cast(Logger::U namespace { -const char * LogLevelStrings[] = { "", "DEBUG", "INFO", "WARNING", "ERROR" }; +const char * LogLevelStrings[] = { "", "DEBUG", "INFO", "WARNING", "ERROR", "OFF" }; #ifndef _WIN32 const int LogLevelSysLog[] = { LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR }; #endif @@ -41,39 +41,16 @@ QAtomicInteger LoggerId = 0; const int MaxRepeatCountSize = 200; QThreadStorage RepeatCount; QThreadStorage RepeatMessage; - -QString getApplicationName() -{ -//#ifdef __GLIBC__ -// const char* _appname_char = program_invocation_short_name; -//#elif !defined(_WIN32) -// const char* _appname_char = getprogname(); -//#else -// char fileName[MAX_PATH]; -// char *_appname_char; -// HINSTANCE hinst = GetModuleHandle(NULL); -// if (GetModuleFileNameA(hinst, fileName, sizeof(fileName))) -// { -// _appname_char = PathFindFileName(fileName); -// *(PathFindExtension(fileName)) = 0; -// } -// else -// _appname_char = "unknown"; -//#endif -// return QString(_appname_char).toLower(); -// - return ""; -} } // namespace -Logger* Logger::getInstance(const QString & name, Logger::LogLevel minLevel) +Logger* Logger::getInstance(const QString & name, const QString & subName, Logger::LogLevel minLevel) { QMutexLocker lock(&MapLock); - Logger* log = LoggerMap.value(name, nullptr); + Logger* log = LoggerMap.value(name + subName, nullptr); if (log == nullptr) { - log = new Logger(name, minLevel); + log = new Logger(name, subName, minLevel); LoggerMap.insert(name, log); // compat version, replace it with following line if we have 100% c++11 //LoggerMap.emplace(name, log); // not compat with older linux distro's e.g. wheezy connect(log, &Logger::newLogMessage, LoggerManager::getInstance(), &LoggerManager::handleNewLogMessage); @@ -82,25 +59,26 @@ Logger* Logger::getInstance(const QString & name, Logger::LogLevel minLevel) return log; } -void Logger::deleteInstance(const QString & name) +void Logger::deleteInstance(const QString & name, const QString & subName) { QMutexLocker lock(&MapLock); if (name.isEmpty()) { - for (auto logger : LoggerMap) + for (auto *logger : qAsConst(LoggerMap)) { delete logger; + } LoggerMap.clear(); } else { - delete LoggerMap.value(name, nullptr); - LoggerMap.remove(name); + delete LoggerMap.value(name + subName, nullptr); + LoggerMap.remove(name + subName); } } -void Logger::setLogLevel(LogLevel level, const QString & name) +void Logger::setLogLevel(LogLevel level, const QString & name, const QString & subName) { if (name.isEmpty()) { @@ -108,26 +86,26 @@ void Logger::setLogLevel(LogLevel level, const QString & name) } else { - Logger* log = Logger::getInstance(name, level); + Logger* log = Logger::getInstance(name, subName, level); log->setMinLevel(level); } } -Logger::LogLevel Logger::getLogLevel(const QString & name) +Logger::LogLevel Logger::getLogLevel(const QString & name, const QString & subName) { if (name.isEmpty()) { return static_cast(int(GLOBAL_MIN_LOG_LEVEL)); } - const Logger* log = Logger::getInstance(name); + const Logger* log = Logger::getInstance(name + subName); return log->getMinLevel(); } -Logger::Logger (const QString & name, LogLevel minLevel) +Logger::Logger (const QString & name, const QString & subName, LogLevel minLevel) : QObject() , _name(name) - , _appname(getApplicationName()) + , _subname(subName) , _syslogEnabled(true) , _loggerId(LoggerId++) , _minLevel(static_cast(minLevel)) @@ -139,7 +117,7 @@ Logger::Logger (const QString & name, LogLevel minLevel) #ifndef _WIN32 if (_syslogEnabled) { - openlog (_appname.toLocal8Bit(), LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0); + openlog (nullptr, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0); } #endif } @@ -172,7 +150,7 @@ void Logger::write(const Logger::T_LOG_MESSAGE & message) .arg(message.function); } - QString name = message.appName + " " + message.loggerName; + QString name = "|" + message.loggerSubName + "| " + message.loggerName; name.resize(MAX_IDENTIFICATION_LENGTH, ' '); const QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(message.utime); @@ -220,6 +198,7 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u }; if (RepeatMessage.localData().loggerName == _name && + RepeatMessage.localData().loggerSubName == _subname && RepeatMessage.localData().function == func && RepeatMessage.localData().message == msg && RepeatMessage.localData().line == line) @@ -236,8 +215,8 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u Logger::T_LOG_MESSAGE logMsg; - logMsg.appName = _appname; logMsg.loggerName = _name; + logMsg.loggerSubName = _subname; logMsg.function = QString(func); logMsg.line = line; logMsg.fileName = FileUtils::getBaseName(sourceFile);