Logging enhancement / fixes (#1419)

* Instance in logging output

* Fix: Trigger that previous log lines are shown in the Log UI
This commit is contained in:
LordGrey 2022-01-22 17:48:03 +01:00 committed by GitHub
parent 98654e48f6
commit 2efc03b612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 158 additions and 122 deletions

View File

@ -121,8 +121,8 @@ $(document).ready(function () {
if (messages.length != 0) { if (messages.length != 0) {
for (var idx = 0; idx < messages.length; idx++) { for (var idx = 0; idx < messages.length; idx++) {
var app_name = messages[idx].appName;
var logger_name = messages[idx].loggerName; var logger_name = messages[idx].loggerName;
var logger_subname = messages[idx].loggerSubName;
var function_ = messages[idx].function; var function_ = messages[idx].function;
var line = messages[idx].line; var line = messages[idx].line;
var file_name = messages[idx].fileName; var file_name = messages[idx].fileName;
@ -136,7 +136,18 @@ $(document).ready(function () {
} }
var date = new Date(parseInt(utime)); 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("<code>" + newLogLine + "</code>\n"); $("#logmessages").append("<code>" + newLogLine + "</code>\n");
} }

View File

@ -256,7 +256,7 @@ public slots:
/// @brief Get a pointer to the priorityMuxer instance /// @brief Get a pointer to the priorityMuxer instance
/// @return PriorityMuxer instance pointer /// @return PriorityMuxer instance pointer
/// ///
PriorityMuxer* getMuxerInstance() { return &_muxer; } PriorityMuxer* getMuxerInstance() { return _muxer; }
/// ///
/// @brief enable/disable automatic/priorized source selection /// @brief enable/disable automatic/priorized source selection
@ -340,7 +340,7 @@ public slots:
/// @brief Get the component Register /// @brief Get the component Register
/// return Component register pointer /// 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 /// @brief Called from components to update their current state. DO NOT CALL FROM USERS
@ -511,7 +511,7 @@ private:
SettingsManager* _settingsManager; SettingsManager* _settingsManager;
/// Register that holds component states /// Register that holds component states
ComponentRegister _componentRegister; ComponentRegister* _componentRegister;
/// The specifiation of the led frame construction and picture integration /// The specifiation of the led frame construction and picture integration
LedString _ledString; LedString _ledString;
@ -522,7 +522,7 @@ private:
std::vector<ColorOrder> _ledStringColorOrder; std::vector<ColorOrder> _ledStringColorOrder;
/// The priority muxer /// The priority muxer
PriorityMuxer _muxer; PriorityMuxer* _muxer;
/// The adjustment from raw colors to led colors /// The adjustment from raw colors to led colors
MultiColorAdjustment * _raw2ledAdjustment; MultiColorAdjustment * _raw2ledAdjustment;

View File

@ -152,6 +152,13 @@ public:
/// ///
static void printLedValues(const std::vector<ColorRgb>& ledValues); static void printLedValues(const std::vector<ColorRgb>& 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: public slots:
/// ///

View File

@ -54,8 +54,8 @@ public:
struct T_LOG_MESSAGE struct T_LOG_MESSAGE
{ {
QString appName;
QString loggerName; QString loggerName;
QString loggerSubName;
QString function; QString function;
unsigned int line; unsigned int line;
QString fileName; QString fileName;
@ -65,22 +65,22 @@ public:
QString levelString; QString levelString;
}; };
static Logger* getInstance(const QString & name = "", LogLevel minLevel=Logger::INFO); static Logger* getInstance(const QString & name = "", const QString & subName = "__", LogLevel minLevel=Logger::INFO);
static void deleteInstance(const QString & name = ""); static void deleteInstance(const QString & name = "", const QString & subName = "__");
static void setLogLevel(LogLevel level, const QString & name = ""); static void setLogLevel(LogLevel level, const QString & name = "", const QString & subName = "__");
static LogLevel getLogLevel(const QString & name = ""); 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 Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...);
void setMinLevel(LogLevel level) { _minLevel = static_cast<int>(level); } void setMinLevel(LogLevel level) { _minLevel = static_cast<int>(level); }
LogLevel getMinLevel() const { return static_cast<LogLevel>(int(_minLevel)); } LogLevel getMinLevel() const { return static_cast<LogLevel>(int(_minLevel)); }
QString getName() const { return _name; } QString getName() const { return _name; }
QString getAppName() const { return _appname; } QString getSubName() const { return _subname; }
signals: signals:
void newLogMessage(Logger::T_LOG_MESSAGE); void newLogMessage(Logger::T_LOG_MESSAGE);
protected: protected:
Logger(const QString & name="", LogLevel minLevel = INFO); Logger(const QString & name="", const QString & subName = "__", LogLevel minLevel = INFO);
~Logger() override; ~Logger() override;
private: private:
@ -95,12 +95,12 @@ private:
static QAtomicInteger<int> GLOBAL_MIN_LOG_LEVEL; static QAtomicInteger<int> GLOBAL_MIN_LOG_LEVEL;
const QString _name; const QString _name;
const QString _appname; const QString _subname;
const bool _syslogEnabled; const bool _syslogEnabled;
const unsigned _loggerId; const unsigned _loggerId;
/* Only non-const member, hence the atomic */ /* Only non-const member, hence the atomic */
QAtomicInteger<int> _minLevel; QAtomicInteger<int> _minLevel;
}; };
class LoggerManager : public QObject class LoggerManager : public QObject

View File

@ -44,12 +44,12 @@ namespace hyperion {
} }
}; };
hyperion->setColor(PriorityMuxer::FG_PRIORITY, fg_color, fg_duration_ms); 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 else
{ {
int result = hyperion->setEffect(fgEffectConfig, PriorityMuxer::FG_PRIORITY, fg_duration_ms); 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 #undef FGCONFIG_ARRAY

View File

@ -72,6 +72,8 @@ API::API(Logger *log, bool localConnection, QObject *parent)
void API::init() void API::init()
{ {
assert(_hyperion);
bool apiAuthRequired = _authManager->isAuthRequired(); bool apiAuthRequired = _authManager->isAuthRequired();
// For security we block external connections if default PW is set // For security we block external connections if default PW is set

View File

@ -617,7 +617,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
// get available components // get available components
QJsonArray component; QJsonArray component;
std::map<hyperion::Components, bool> components = _hyperion->getComponentRegister().getRegister(); std::map<hyperion::Components, bool> components = _hyperion->getComponentRegister()->getRegister();
for (auto comp : components) for (auto comp : components)
{ {
QJsonObject item; QJsonObject item;
@ -1154,7 +1154,9 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co
{ {
_streaming_logging_reply["command"] = command + "-update"; _streaming_logging_reply["command"] = command + "-update";
connect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage); 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") else if (subcommand == "stop")
@ -1783,22 +1785,26 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
const QList<Logger::T_LOG_MESSAGE> *logBuffer = LoggerManager::getInstance()->getLogMessageBuffer(); const QList<Logger::T_LOG_MESSAGE> *logBuffer = LoggerManager::getInstance()->getLogMessageBuffer();
for (int i = 0; i < logBuffer->length(); i++) for (int i = 0; i < logBuffer->length(); i++)
{ {
message["appName"] = logBuffer->at(i).appName; //Only present records of the current log-level
message["loggerName"] = logBuffer->at(i).loggerName; if ( logBuffer->at(i).level >= _log->getLogLevel())
message["function"] = logBuffer->at(i).function; {
message["line"] = QString::number(logBuffer->at(i).line); message["loggerName"] = logBuffer->at(i).loggerName;
message["fileName"] = logBuffer->at(i).fileName; message["loggerSubName"] = logBuffer->at(i).loggerSubName;
message["message"] = logBuffer->at(i).message; message["function"] = logBuffer->at(i).function;
message["levelString"] = logBuffer->at(i).levelString; message["line"] = QString::number(logBuffer->at(i).line);
message["utime"] = QString::number(logBuffer->at(i).utime); 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 else
{ {
message["appName"] = msg.appName;
message["loggerName"] = msg.loggerName; message["loggerName"] = msg.loggerName;
message["loggerSubName"] = msg.loggerSubName;
message["function"] = msg.function; message["function"] = msg.function;
message["line"] = QString::number(msg.line); message["line"] = QString::number(msg.line);
message["fileName"] = msg.fileName; message["fileName"] = msg.fileName;

View File

@ -156,6 +156,7 @@ void JsonCB::resetSubscriptions()
void JsonCB::setSubscriptionsTo(Hyperion* hyperion) void JsonCB::setSubscriptionsTo(Hyperion* hyperion)
{ {
assert(hyperion);
//std::cout << "JsonCB::setSubscriptions for instance [" << static_cast<int>(hyperion->getInstanceIndex()) << "] " << std::endl; //std::cout << "JsonCB::setSubscriptions for instance [" << static_cast<int>(hyperion->getInstanceIndex()) << "] " << std::endl;
// get current subs // get current subs
@ -166,7 +167,7 @@ void JsonCB::setSubscriptionsTo(Hyperion* hyperion)
// update pointer // update pointer
_hyperion = hyperion; _hyperion = hyperion;
_componentRegister = &_hyperion->getComponentRegister(); _componentRegister = _hyperion->getComponentRegister();
_prioMuxer = _hyperion->getMuxerInstance(); _prioMuxer = _hyperion->getMuxerInstance();
// re-apply subs // re-apply subs

View File

@ -69,7 +69,7 @@ void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJson
_detector = new BlackBorderDetector(newThreshold); _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 // eval the comp state
handleCompStateChangeRequest(hyperion::COMP_BLACKBORDER, obj["enable"].toBool(true)); handleCompStateChangeRequest(hyperion::COMP_BLACKBORDER, obj["enable"].toBool(true));

View File

@ -19,9 +19,12 @@
EffectEngine::EffectEngine(Hyperion * hyperion) EffectEngine::EffectEngine(Hyperion * hyperion)
: _hyperion(hyperion) : _hyperion(hyperion)
, _log(Logger::getInstance("EFFECTENGINE")) , _log(nullptr)
, _effectFileHandler(EffectFileHandler::getInstance()) , _effectFileHandler(EffectFileHandler::getInstance())
{ {
QString subComponent = hyperion->property("instance").toString();
_log= Logger::getInstance("EFFECTENGINE", subComponent);
Q_INIT_RESOURCE(EffectEngine); Q_INIT_RESOURCE(EffectEngine);
qRegisterMetaType<hyperion::Components>("hyperion::Components"); qRegisterMetaType<hyperion::Components>("hyperion::Components");

View File

@ -21,11 +21,14 @@
MessageForwarder::MessageForwarder(Hyperion* hyperion) MessageForwarder::MessageForwarder(Hyperion* hyperion)
: _hyperion(hyperion) : _hyperion(hyperion)
, _log(Logger::getInstance("NETFORWARDER")) , _log(nullptr)
, _muxer(_hyperion->getMuxerInstance()) , _muxer(_hyperion->getMuxerInstance())
, _forwarder_enabled(true) , _forwarder_enabled(true)
, _priority(140) , _priority(140)
{ {
QString subComponent = hyperion->property("instance").toString();
_log= Logger::getInstance("NETFORWARDER", subComponent);
// get settings updates // get settings updates
connect(_hyperion, &Hyperion::settingsChanged, this, &MessageForwarder::handleSettingsUpdate); connect(_hyperion, &Hyperion::settingsChanged, this, &MessageForwarder::handleSettingsUpdate);

View File

@ -9,8 +9,11 @@ using namespace hyperion;
ComponentRegister::ComponentRegister(Hyperion* hyperion) ComponentRegister::ComponentRegister(Hyperion* hyperion)
: _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 // init all comps to false
QVector<hyperion::Components> vect; QVector<hyperion::Components> vect;
vect << COMP_ALL << COMP_SMOOTHING << COMP_LEDDEVICE; vect << COMP_ALL << COMP_SMOOTHING << COMP_LEDDEVICE;

View File

@ -49,10 +49,10 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
: QObject() : QObject()
, _instIndex(instance) , _instIndex(instance)
, _settingsManager(new SettingsManager(instance, this, readonlyMode)) , _settingsManager(new SettingsManager(instance, this, readonlyMode))
, _componentRegister(this) , _componentRegister(nullptr)
, _ledString(hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object()))) , _ledString(hyperion::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
, _imageProcessor(new ImageProcessor(_ledString, this)) , _imageProcessor(nullptr)
, _muxer(static_cast<int>(_ledString.leds().size()), this) , _muxer(nullptr)
, _raw2ledAdjustment(hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object())) , _raw2ledAdjustment(hyperion::createLedColorsAdjustment(static_cast<int>(_ledString.leds().size()), getSetting(settings::COLOR).object()))
, _ledDeviceWrapper(nullptr) , _ledDeviceWrapper(nullptr)
, _deviceSmooth(nullptr) , _deviceSmooth(nullptr)
@ -60,7 +60,7 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
#if defined(ENABLE_FORWARDER) #if defined(ENABLE_FORWARDER)
, _messageForwarder(nullptr) , _messageForwarder(nullptr)
#endif #endif
, _log(Logger::getInstance("HYPERION")) , _log(nullptr)
, _hwLedCount() , _hwLedCount()
, _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array())) , _ledGridSize(hyperion::getLedLayoutGridSize(getSetting(settings::LEDS).array()))
, _BGEffectHandler(nullptr) , _BGEffectHandler(nullptr)
@ -71,7 +71,14 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
#endif #endif
, _readOnlyMode(readonlyMode) , _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<int>(_ledString.leds().size()), this);
} }
Hyperion::~Hyperion() Hyperion::~Hyperion()
@ -102,9 +109,9 @@ void Hyperion::start()
} }
// connect Hyperion::update with Muxer visible priority changes as muxer updates independent // 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::update);
connect(&_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability); connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability);
connect(&_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged); connect(_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions // listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
// connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState); // connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState);
@ -199,6 +206,10 @@ void Hyperion::freeObjects()
delete _settingsManager; delete _settingsManager;
delete _ledDeviceWrapper; delete _ledDeviceWrapper;
delete _imageProcessor;
delete _muxer;
delete _componentRegister;
} }
void Hyperion::handleSettingsUpdate(settings::type type, const QJsonDocument& config) 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, img processor, muxer, ledGridSize (effect-engine image based effects), _ledBuffer and ByteOrder of ledstring
_ledString = hyperion::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object())); _ledString = hyperion::createLedString(leds, hyperion::createColorOrder(getSetting(settings::DEVICE).object()));
_imageProcessor->setLedString(_ledString); _imageProcessor->setLedString(_ledString);
_muxer.updateLedColorsLength(static_cast<int>(_ledString.leds().size())); _muxer->updateLedColorsLength(static_cast<int>(_ledString.leds().size()));
_ledGridSize = hyperion::getLedLayoutGridSize(leds); _ledGridSize = hyperion::getLedLayoutGridSize(leds);
std::vector<ColorRgb> color(_ledString.leds().size(), ColorRgb{0,0,0}); std::vector<ColorRgb> color(_ledString.leds().size(), ColorRgb{0,0,0});
@ -322,42 +333,42 @@ int Hyperion::getLedCount() const
void Hyperion::setSourceAutoSelect(bool state) void Hyperion::setSourceAutoSelect(bool state)
{ {
_muxer.setSourceAutoSelectEnabled(state); _muxer->setSourceAutoSelectEnabled(state);
} }
bool Hyperion::setVisiblePriority(int priority) bool Hyperion::setVisiblePriority(int priority)
{ {
return _muxer.setPriority(priority); return _muxer->setPriority(priority);
} }
bool Hyperion::sourceAutoSelectEnabled() const bool Hyperion::sourceAutoSelectEnabled() const
{ {
return _muxer.isSourceAutoSelectEnabled(); return _muxer->isSourceAutoSelectEnabled();
} }
void Hyperion::setNewComponentState(hyperion::Components component, bool state) void Hyperion::setNewComponentState(hyperion::Components component, bool state)
{ {
_componentRegister.setNewComponentState(component, state); _componentRegister->setNewComponentState(component, state);
} }
std::map<hyperion::Components, bool> Hyperion::getAllComponents() const std::map<hyperion::Components, bool> Hyperion::getAllComponents() const
{ {
return _componentRegister.getRegister(); return _componentRegister->getRegister();
} }
int Hyperion::isComponentEnabled(hyperion::Components comp) const 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) 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<ColorRgb>& ledColors, int timeout_ms, bool clearEffect) bool Hyperion::setInput(int priority, const std::vector<ColorRgb>& 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 // clear effect if this call does not come from an effect
if(clearEffect) if(clearEffect)
@ -366,7 +377,7 @@ bool Hyperion::setInput(int priority, const std::vector<ColorRgb>& ledColors, in
} }
// if this priority is visible, update immediately // if this priority is visible, update immediately
if(priority == _muxer.getCurrentPriority()) if(priority == _muxer->getCurrentPriority())
{ {
update(); update();
} }
@ -378,13 +389,13 @@ bool Hyperion::setInput(int priority, const std::vector<ColorRgb>& ledColors, in
bool Hyperion::setInputImage(int priority, const Image<ColorRgb>& image, int64_t timeout_ms, bool clearEffect) bool Hyperion::setInputImage(int priority, const Image<ColorRgb>& image, int64_t timeout_ms, bool clearEffect)
{ {
if (!_muxer.hasPriority(priority)) if (!_muxer->hasPriority(priority))
{ {
emit GlobalSignals::getInstance()->globalRegRequired(priority); emit GlobalSignals::getInstance()->globalRegRequired(priority);
return false; 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 // clear effect if this call does not come from an effect
if(clearEffect) if(clearEffect)
@ -393,7 +404,7 @@ bool Hyperion::setInputImage(int priority, const Image<ColorRgb>& image, int64_t
} }
// if this priority is visible, update immediately // if this priority is visible, update immediately
if(priority == _muxer.getCurrentPriority()) if(priority == _muxer->getCurrentPriority())
{ {
update(); update();
} }
@ -405,7 +416,7 @@ bool Hyperion::setInputImage(int priority, const Image<ColorRgb>& image, int64_t
bool Hyperion::setInputInactive(quint8 priority) bool Hyperion::setInputInactive(quint8 priority)
{ {
return _muxer.setInputInactive(priority); return _muxer->setInputInactive(priority);
} }
void Hyperion::setColor(int priority, const std::vector<ColorRgb> &ledColors, int timeout_ms, const QString &origin, bool clearEffects) void Hyperion::setColor(int priority, const std::vector<ColorRgb> &ledColors, int timeout_ms, const QString &origin, bool clearEffects)
@ -465,7 +476,7 @@ bool Hyperion::clear(int priority, bool forceClearAll)
bool isCleared = false; bool isCleared = false;
if (priority < 0) if (priority < 0)
{ {
_muxer.clearAll(forceClearAll); _muxer->clearAll(forceClearAll);
// send clearall signal to the effect engine // send clearall signal to the effect engine
_effectEngine->allChannelsCleared(); _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) // (outside the check so the effect gets cleared even when the effect is not sending colors)
_effectEngine->channelCleared(priority); _effectEngine->channelCleared(priority);
if (_muxer.clearInput(priority)) if (_muxer->clearInput(priority))
{ {
isCleared = true; isCleared = true;
} }
@ -487,7 +498,7 @@ bool Hyperion::clear(int priority, bool forceClearAll)
int Hyperion::getCurrentPriority() const int Hyperion::getCurrentPriority() const
{ {
return _muxer.getCurrentPriority(); return _muxer->getCurrentPriority();
} }
bool Hyperion::isCurrentPriority(int priority) const bool Hyperion::isCurrentPriority(int priority) const
@ -497,12 +508,12 @@ bool Hyperion::isCurrentPriority(int priority) const
QList<int> Hyperion::getActivePriorities() const QList<int> Hyperion::getActivePriorities() const
{ {
return _muxer.getPriorities(); return _muxer->getPriorities();
} }
Hyperion::InputInfo Hyperion::getPriorityInfo(int priority) const Hyperion::InputInfo Hyperion::getPriorityInfo(int priority) const
{ {
return _muxer.getInputInfo(priority); return _muxer->getInputInfo(priority);
} }
QString Hyperion::saveEffect(const QJsonObject& obj) QString Hyperion::saveEffect(const QJsonObject& obj)
@ -582,7 +593,7 @@ void Hyperion::handleVisibleComponentChanged(hyperion::Components comp)
} }
void Hyperion::handleSourceAvailability(const quint8& priority) void Hyperion::handleSourceAvailability(const quint8& priority)
{ int previousPriority = _muxer.getPreviousPriority(); { int previousPriority = _muxer->getPreviousPriority();
Debug(_log,"priority[%d], previousPriority[%d]", priority, previousPriority); Debug(_log,"priority[%d], previousPriority[%d]", priority, previousPriority);
if ( priority == PriorityMuxer::LOWEST_PRIORITY) if ( priority == PriorityMuxer::LOWEST_PRIORITY)
@ -605,8 +616,8 @@ void Hyperion::handleSourceAvailability(const quint8& priority)
void Hyperion::update() void Hyperion::update()
{ {
// Obtain the current priority channel // Obtain the current priority channel
int priority = _muxer.getCurrentPriority(); int priority = _muxer->getCurrentPriority();
const PriorityMuxer::InputInfo priorityInfo = _muxer.getInputInfo(priority); const PriorityMuxer::InputInfo priorityInfo = _muxer->getInputInfo(priority);
// copy image & process OR copy ledColors from muxer // copy image & process OR copy ledColors from muxer
Image<ColorRgb> image = priorityInfo.image; Image<ColorRgb> image = priorityInfo.image;

View File

@ -11,7 +11,7 @@ HyperionIManager* HyperionIManager::HIMinstance;
HyperionIManager::HyperionIManager(const QString& rootPath, QObject* parent, bool readonlyMode) HyperionIManager::HyperionIManager(const QString& rootPath, QObject* parent, bool readonlyMode)
: QObject(parent) : QObject(parent)
, _log(Logger::getInstance("HYPERION")) , _log(Logger::getInstance("HYPERION-INSTMGR"))
, _instanceTable( new InstanceTable(rootPath, this, readonlyMode) ) , _instanceTable( new InstanceTable(rootPath, this, readonlyMode) )
, _rootPath( rootPath ) , _rootPath( rootPath )
, _readonlyMode(readonlyMode) , _readonlyMode(readonlyMode)

View File

@ -28,7 +28,7 @@ QString ImageProcessor::mappingTypeToStr(int mappingType)
ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion) ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion)
: QObject(hyperion) : QObject(hyperion)
, _log(Logger::getInstance("IMAGETOLED")) , _log(nullptr)
, _ledString(ledString) , _ledString(ledString)
, _borderProcessor(new BlackBorderProcessor(hyperion, this)) , _borderProcessor(new BlackBorderProcessor(hyperion, this))
, _imageToLeds(nullptr) , _imageToLeds(nullptr)
@ -37,6 +37,9 @@ ImageProcessor::ImageProcessor(const LedString& ledString, Hyperion* hyperion)
, _hardMappingType(0) , _hardMappingType(0)
, _hyperion(hyperion) , _hyperion(hyperion)
{ {
QString subComponent = hyperion->property("instance").toString();
_log= Logger::getInstance("IMAGETOLED", subComponent);
// init // init
handleSettingsUpdate(settings::COLOR, _hyperion->getSetting(settings::COLOR)); handleSettingsUpdate(settings::COLOR, _hyperion->getSetting(settings::COLOR));
// listen for changes in color - ledmapping // listen for changes in color - ledmapping

View File

@ -50,7 +50,7 @@ const unsigned DEFAUL_OUTPUTDEPLAY = 0; // outputdelay in ms
LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion) LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion *hyperion)
: QObject(hyperion) : QObject(hyperion)
, _log(Logger::getInstance("SMOOTHING")) , _log(nullptr)
, _hyperion(hyperion) , _hyperion(hyperion)
, _updateInterval(DEFAUL_UPDATEINTERVALL.count()) , _updateInterval(DEFAUL_UPDATEINTERVALL.count())
, _settlingTime(DEFAUL_SETTLINGTIME) , _settlingTime(DEFAUL_SETTLINGTIME)
@ -62,6 +62,9 @@ LinearColorSmoothing::LinearColorSmoothing(const QJsonDocument &config, Hyperion
, _enabled(false) , _enabled(false)
, tempValues(std::vector<uint64_t>(0, 0L)) , tempValues(std::vector<uint64_t>(0, 0L))
{ {
QString subComponent = hyperion->property("instance").toString();
_log= Logger::getInstance("SMOOTHING", subComponent);
// init cfg 0 (default) // init cfg 0 (default)
addConfig(DEFAUL_SETTLINGTIME, DEFAUL_UPDATEFREQUENCY, DEFAUL_OUTPUTDEPLAY); addConfig(DEFAUL_SETTLINGTIME, DEFAUL_UPDATEFREQUENCY, DEFAUL_OUTPUTDEPLAY);
handleSettingsUpdate(settings::SMOOTHING, config); handleSettingsUpdate(settings::SMOOTHING, config);

View File

@ -20,7 +20,7 @@ const int PriorityMuxer::TIMEOUT_NOT_ACTIVE_PRIO = -100;
PriorityMuxer::PriorityMuxer(int ledCount, QObject * parent) PriorityMuxer::PriorityMuxer(int ledCount, QObject * parent)
: QObject(parent) : QObject(parent)
, _log(Logger::getInstance("HYPERION")) , _log(nullptr)
, _currentPriority(PriorityMuxer::LOWEST_PRIORITY) , _currentPriority(PriorityMuxer::LOWEST_PRIORITY)
, _previousPriority(_currentPriority) , _previousPriority(_currentPriority)
, _manualSelectedPriority(MANUAL_SELECTED_PRIORITY) , _manualSelectedPriority(MANUAL_SELECTED_PRIORITY)
@ -32,6 +32,9 @@ PriorityMuxer::PriorityMuxer(int ledCount, QObject * parent)
, _timer(new QTimer(this)) , _timer(new QTimer(this))
, _blockTimer(new QTimer(this)) , _blockTimer(new QTimer(this))
{ {
QString subComponent = parent->property("instance").toString();
_log= Logger::getInstance("MUXER", subComponent);
// init lowest priority info // init lowest priority info
_lowestPriorityInfo.priority = PriorityMuxer::LOWEST_PRIORITY; _lowestPriorityInfo.priority = PriorityMuxer::LOWEST_PRIORITY;
_lowestPriorityInfo.timeoutTime_ms = -1; _lowestPriorityInfo.timeoutTime_ms = -1;

View File

@ -28,7 +28,7 @@ QJsonObject SettingsManager::schemaJson;
SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonlyMode) SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonlyMode)
: QObject(parent) : QObject(parent)
, _log(Logger::getInstance("SETTINGSMGR")) , _log(Logger::getInstance("SETTINGSMGR", "I"+QString::number(instance)))
, _instance(instance) , _instance(instance)
, _sTable(new SettingsTable(instance, this)) , _sTable(new SettingsTable(instance, this))
, _configVersion(DEFAULT_VERSION) , _configVersion(DEFAULT_VERSION)
@ -628,6 +628,8 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
{ {
newJsonConfig["port"] = 19444; newJsonConfig["port"] = 19444;
} }
newJsonConfig["name"] = host;
json.append(newJsonConfig); json.append(newJsonConfig);
migrated = true; migrated = true;
} }
@ -636,13 +638,10 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
if (!json.isEmpty()) if (!json.isEmpty())
{ {
newForwarderConfig["json"] = json; newForwarderConfig["jsonapi"] = json;
}
else
{
newForwarderConfig.remove("json");
migrated = true;
} }
newForwarderConfig.remove("json");
migrated = true;
} }
QJsonArray flatbuffer; QJsonArray flatbuffer;
@ -672,6 +671,7 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
{ {
newFlattbufferConfig["port"] = 19400; newFlattbufferConfig["port"] = 19400;
} }
newFlattbufferConfig["name"] = host;
flatbuffer.append(newFlattbufferConfig); flatbuffer.append(newFlattbufferConfig);
migrated = true; migrated = true;
@ -680,13 +680,10 @@ bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
if (!flatbuffer.isEmpty()) if (!flatbuffer.isEmpty())
{ {
newForwarderConfig["flat"] = flatbuffer; newForwarderConfig["flatbuffer"] = flatbuffer;
}
else
{
newForwarderConfig.remove("flat");
migrated = true;
} }
newForwarderConfig.remove("flat");
migrated = true;
} }
} }

View File

@ -56,6 +56,10 @@ void LedDeviceWrapper::createLedDevice(const QJsonObject& config)
QThread* thread = new QThread(this); QThread* thread = new QThread(this);
thread->setObjectName("LedDeviceThread"); thread->setObjectName("LedDeviceThread");
_ledDevice = LedDeviceFactory::construct(config); _ledDevice = LedDeviceFactory::construct(config);
QString subComponent = parent()->property("instance").toString();
_ledDevice->setLogger(Logger::getInstance("LEDDEVICE", subComponent));
_ledDevice->moveToThread(thread); _ledDevice->moveToThread(thread);
// setup thread management // setup thread management
connect(thread, &QThread::started, _ledDevice, &LedDevice::start); connect(thread, &QThread::started, _ledDevice, &LedDevice::start);
@ -92,13 +96,13 @@ QJsonObject LedDeviceWrapper::getLedDeviceSchemas()
QString devName = item.remove("schema-"); QString devName = item.remove("schema-");
QString data; 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()); throw std::runtime_error("ERROR: Schema not found: " + item.toStdString());
} }
QJsonObject schema; 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()); throw std::runtime_error("ERROR: JSON schema wrong of file: " + item.toStdString());
} }

View File

@ -28,7 +28,7 @@ QAtomicInteger<int> Logger::GLOBAL_MIN_LOG_LEVEL { static_cast<int>(Logger::U
namespace namespace
{ {
const char * LogLevelStrings[] = { "", "DEBUG", "INFO", "WARNING", "ERROR" }; const char * LogLevelStrings[] = { "", "DEBUG", "INFO", "WARNING", "ERROR", "OFF" };
#ifndef _WIN32 #ifndef _WIN32
const int LogLevelSysLog[] = { LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR }; const int LogLevelSysLog[] = { LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR };
#endif #endif
@ -41,39 +41,16 @@ QAtomicInteger<unsigned int> LoggerId = 0;
const int MaxRepeatCountSize = 200; const int MaxRepeatCountSize = 200;
QThreadStorage<int> RepeatCount; QThreadStorage<int> RepeatCount;
QThreadStorage<Logger::T_LOG_MESSAGE> RepeatMessage; QThreadStorage<Logger::T_LOG_MESSAGE> 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 } // 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); QMutexLocker lock(&MapLock);
Logger* log = LoggerMap.value(name, nullptr); Logger* log = LoggerMap.value(name + subName, nullptr);
if (log == 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.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 //LoggerMap.emplace(name, log); // not compat with older linux distro's e.g. wheezy
connect(log, &Logger::newLogMessage, LoggerManager::getInstance(), &LoggerManager::handleNewLogMessage); connect(log, &Logger::newLogMessage, LoggerManager::getInstance(), &LoggerManager::handleNewLogMessage);
@ -82,25 +59,26 @@ Logger* Logger::getInstance(const QString & name, Logger::LogLevel minLevel)
return log; return log;
} }
void Logger::deleteInstance(const QString & name) void Logger::deleteInstance(const QString & name, const QString & subName)
{ {
QMutexLocker lock(&MapLock); QMutexLocker lock(&MapLock);
if (name.isEmpty()) if (name.isEmpty())
{ {
for (auto logger : LoggerMap) for (auto *logger : qAsConst(LoggerMap)) {
delete logger; delete logger;
}
LoggerMap.clear(); LoggerMap.clear();
} }
else else
{ {
delete LoggerMap.value(name, nullptr); delete LoggerMap.value(name + subName, nullptr);
LoggerMap.remove(name); 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()) if (name.isEmpty())
{ {
@ -108,26 +86,26 @@ void Logger::setLogLevel(LogLevel level, const QString & name)
} }
else else
{ {
Logger* log = Logger::getInstance(name, level); Logger* log = Logger::getInstance(name, subName, level);
log->setMinLevel(level); log->setMinLevel(level);
} }
} }
Logger::LogLevel Logger::getLogLevel(const QString & name) Logger::LogLevel Logger::getLogLevel(const QString & name, const QString & subName)
{ {
if (name.isEmpty()) if (name.isEmpty())
{ {
return static_cast<Logger::LogLevel>(int(GLOBAL_MIN_LOG_LEVEL)); return static_cast<Logger::LogLevel>(int(GLOBAL_MIN_LOG_LEVEL));
} }
const Logger* log = Logger::getInstance(name); const Logger* log = Logger::getInstance(name + subName);
return log->getMinLevel(); return log->getMinLevel();
} }
Logger::Logger (const QString & name, LogLevel minLevel) Logger::Logger (const QString & name, const QString & subName, LogLevel minLevel)
: QObject() : QObject()
, _name(name) , _name(name)
, _appname(getApplicationName()) , _subname(subName)
, _syslogEnabled(true) , _syslogEnabled(true)
, _loggerId(LoggerId++) , _loggerId(LoggerId++)
, _minLevel(static_cast<int>(minLevel)) , _minLevel(static_cast<int>(minLevel))
@ -139,7 +117,7 @@ Logger::Logger (const QString & name, LogLevel minLevel)
#ifndef _WIN32 #ifndef _WIN32
if (_syslogEnabled) if (_syslogEnabled)
{ {
openlog (_appname.toLocal8Bit(), LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0); openlog (nullptr, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0);
} }
#endif #endif
} }
@ -172,7 +150,7 @@ void Logger::write(const Logger::T_LOG_MESSAGE & message)
.arg(message.function); .arg(message.function);
} }
QString name = message.appName + " " + message.loggerName; QString name = "|" + message.loggerSubName + "| " + message.loggerName;
name.resize(MAX_IDENTIFICATION_LENGTH, ' '); name.resize(MAX_IDENTIFICATION_LENGTH, ' ');
const QDateTime timestamp = QDateTime::fromMSecsSinceEpoch(message.utime); 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 && if (RepeatMessage.localData().loggerName == _name &&
RepeatMessage.localData().loggerSubName == _subname &&
RepeatMessage.localData().function == func && RepeatMessage.localData().function == func &&
RepeatMessage.localData().message == msg && RepeatMessage.localData().message == msg &&
RepeatMessage.localData().line == line) 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; Logger::T_LOG_MESSAGE logMsg;
logMsg.appName = _appname;
logMsg.loggerName = _name; logMsg.loggerName = _name;
logMsg.loggerSubName = _subname;
logMsg.function = QString(func); logMsg.function = QString(func);
logMsg.line = line; logMsg.line = line;
logMsg.fileName = FileUtils::getBaseName(sourceFile); logMsg.fileName = FileUtils::getBaseName(sourceFile);