Skip to content

Commit 2efc03b

Browse files
authored
Logging enhancement / fixes (#1419)
* Instance in logging output * Fix: Trigger that previous log lines are shown in the Log UI
1 parent 98654e4 commit 2efc03b

File tree

20 files changed

+159
-123
lines changed

20 files changed

+159
-123
lines changed

assets/webconfig/js/content_logging.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ $(document).ready(function () {
121121
if (messages.length != 0) {
122122

123123
for (var idx = 0; idx < messages.length; idx++) {
124-
var app_name = messages[idx].appName;
125124
var logger_name = messages[idx].loggerName;
125+
var logger_subname = messages[idx].loggerSubName;
126126
var function_ = messages[idx].function;
127127
var line = messages[idx].line;
128128
var file_name = messages[idx].fileName;
@@ -136,7 +136,18 @@ $(document).ready(function () {
136136
}
137137

138138
var date = new Date(parseInt(utime));
139-
var newLogLine = date.toISOString() + " [" + app_name + " " + logger_name + "] (" + level_string + ") " + debug + msg;
139+
var subComponent = "";
140+
if (window.serverInfo.instance.length > 1) {
141+
if (logger_subname.startsWith("I")) {
142+
var instanceNum = logger_subname.substring(1);
143+
if (window.serverInfo.instance[instanceNum]) {
144+
subComponent = window.serverInfo.instance[instanceNum].friendly_name;
145+
} else {
146+
subComponent = instanceNum;
147+
}
148+
}
149+
}
150+
var newLogLine = date.toISOString() + " [" + logger_name + (subComponent ? "|" + subComponent : "") + "] (" + level_string + ") " + debug + msg;
140151

141152
$("#logmessages").append("<code>" + newLogLine + "</code>\n");
142153
}

include/hyperion/Hyperion.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public slots:
256256
/// @brief Get a pointer to the priorityMuxer instance
257257
/// @return PriorityMuxer instance pointer
258258
///
259-
PriorityMuxer* getMuxerInstance() { return &_muxer; }
259+
PriorityMuxer* getMuxerInstance() { return _muxer; }
260260

261261
///
262262
/// @brief enable/disable automatic/priorized source selection
@@ -340,7 +340,7 @@ public slots:
340340
/// @brief Get the component Register
341341
/// return Component register pointer
342342
///
343-
ComponentRegister & getComponentRegister() { return _componentRegister; }
343+
ComponentRegister* getComponentRegister() { return _componentRegister; }
344344

345345
///
346346
/// @brief Called from components to update their current state. DO NOT CALL FROM USERS
@@ -511,7 +511,7 @@ private slots:
511511
SettingsManager* _settingsManager;
512512

513513
/// Register that holds component states
514-
ComponentRegister _componentRegister;
514+
ComponentRegister* _componentRegister;
515515

516516
/// The specifiation of the led frame construction and picture integration
517517
LedString _ledString;
@@ -522,7 +522,7 @@ private slots:
522522
std::vector<ColorOrder> _ledStringColorOrder;
523523

524524
/// The priority muxer
525-
PriorityMuxer _muxer;
525+
PriorityMuxer* _muxer;
526526

527527
/// The adjustment from raw colors to led colors
528528
MultiColorAdjustment * _raw2ledAdjustment;

include/leddevice/LedDevice.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ class LedDevice : public QObject
152152
///
153153
static void printLedValues(const std::vector<ColorRgb>& ledValues);
154154

155+
///
156+
/// @brief Set the common logger for LED-devices.
157+
///
158+
/// @param[in] log The logger to be used
159+
///
160+
void setLogger(Logger* log) { _log = log; }
161+
155162
public slots:
156163

157164
///

include/utils/Logger.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Logger : public QObject
5454

5555
struct T_LOG_MESSAGE
5656
{
57-
QString appName;
5857
QString loggerName;
58+
QString loggerSubName;
5959
QString function;
6060
unsigned int line;
6161
QString fileName;
@@ -65,22 +65,22 @@ class Logger : public QObject
6565
QString levelString;
6666
};
6767

68-
static Logger* getInstance(const QString & name = "", LogLevel minLevel=Logger::INFO);
69-
static void deleteInstance(const QString & name = "");
70-
static void setLogLevel(LogLevel level, const QString & name = "");
71-
static LogLevel getLogLevel(const QString & name = "");
68+
static Logger* getInstance(const QString & name = "", const QString & subName = "__", LogLevel minLevel=Logger::INFO);
69+
static void deleteInstance(const QString & name = "", const QString & subName = "__");
70+
static void setLogLevel(LogLevel level, const QString & name = "", const QString & subName = "__");
71+
static LogLevel getLogLevel(const QString & name = "", const QString & subName = "__");
7272

7373
void Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...);
7474
void setMinLevel(LogLevel level) { _minLevel = static_cast<int>(level); }
7575
LogLevel getMinLevel() const { return static_cast<LogLevel>(int(_minLevel)); }
7676
QString getName() const { return _name; }
77-
QString getAppName() const { return _appname; }
77+
QString getSubName() const { return _subname; }
7878

7979
signals:
8080
void newLogMessage(Logger::T_LOG_MESSAGE);
8181

8282
protected:
83-
Logger(const QString & name="", LogLevel minLevel = INFO);
83+
Logger(const QString & name="", const QString & subName = "__", LogLevel minLevel = INFO);
8484
~Logger() override;
8585

8686
private:
@@ -95,12 +95,12 @@ class Logger : public QObject
9595
static QAtomicInteger<int> GLOBAL_MIN_LOG_LEVEL;
9696

9797
const QString _name;
98-
const QString _appname;
98+
const QString _subname;
9999
const bool _syslogEnabled;
100100
const unsigned _loggerId;
101101

102102
/* Only non-const member, hence the atomic */
103-
QAtomicInteger<int> _minLevel;
103+
QAtomicInteger<int> _minLevel;
104104
};
105105

106106
class LoggerManager : public QObject

include/utils/hyperion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ namespace hyperion {
4444
}
4545
};
4646
hyperion->setColor(PriorityMuxer::FG_PRIORITY, fg_color, fg_duration_ms);
47-
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);
47+
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);
4848
}
4949
else
5050
{
5151
int result = hyperion->setEffect(fgEffectConfig, PriorityMuxer::FG_PRIORITY, fg_duration_ms);
52-
Info(Logger::getInstance("HYPERION"),"Initial foreground effect '%s' %s", QSTRING_CSTR(fgEffectConfig), ((result == 0) ? "started" : "failed"));
52+
Info(Logger::getInstance("HYPERION","I"+QString::number(hyperion->getInstanceIndex())),"Initial foreground effect '%s' %s", QSTRING_CSTR(fgEffectConfig), ((result == 0) ? "started" : "failed"));
5353
}
5454
}
5555
#undef FGCONFIG_ARRAY

libsrc/api/API.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ API::API(Logger *log, bool localConnection, QObject *parent)
7272

7373
void API::init()
7474
{
75+
assert(_hyperion);
76+
7577
bool apiAuthRequired = _authManager->isAuthRequired();
7678

7779
// For security we block external connections if default PW is set

libsrc/api/JsonAPI.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
617617

618618
// get available components
619619
QJsonArray component;
620-
std::map<hyperion::Components, bool> components = _hyperion->getComponentRegister().getRegister();
620+
std::map<hyperion::Components, bool> components = _hyperion->getComponentRegister()->getRegister();
621621
for (auto comp : components)
622622
{
623623
QJsonObject item;
@@ -1154,7 +1154,9 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co
11541154
{
11551155
_streaming_logging_reply["command"] = command + "-update";
11561156
connect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage);
1157-
Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); // needed to trigger log sending
1157+
1158+
emit incommingLogMessage (Logger::T_LOG_MESSAGE{}); // needed to trigger log sending
1159+
Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str());
11581160
}
11591161
}
11601162
else if (subcommand == "stop")
@@ -1783,22 +1785,26 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
17831785
const QList<Logger::T_LOG_MESSAGE> *logBuffer = LoggerManager::getInstance()->getLogMessageBuffer();
17841786
for (int i = 0; i < logBuffer->length(); i++)
17851787
{
1786-
message["appName"] = logBuffer->at(i).appName;
1787-
message["loggerName"] = logBuffer->at(i).loggerName;
1788-
message["function"] = logBuffer->at(i).function;
1789-
message["line"] = QString::number(logBuffer->at(i).line);
1790-
message["fileName"] = logBuffer->at(i).fileName;
1791-
message["message"] = logBuffer->at(i).message;
1792-
message["levelString"] = logBuffer->at(i).levelString;
1793-
message["utime"] = QString::number(logBuffer->at(i).utime);
1794-
1795-
messageArray.append(message);
1788+
//Only present records of the current log-level
1789+
if ( logBuffer->at(i).level >= _log->getLogLevel())
1790+
{
1791+
message["loggerName"] = logBuffer->at(i).loggerName;
1792+
message["loggerSubName"] = logBuffer->at(i).loggerSubName;
1793+
message["function"] = logBuffer->at(i).function;
1794+
message["line"] = QString::number(logBuffer->at(i).line);
1795+
message["fileName"] = logBuffer->at(i).fileName;
1796+
message["message"] = logBuffer->at(i).message;
1797+
message["levelString"] = logBuffer->at(i).levelString;
1798+
message["utime"] = QString::number(logBuffer->at(i).utime);
1799+
1800+
messageArray.append(message);
1801+
}
17961802
}
17971803
}
17981804
else
17991805
{
1800-
message["appName"] = msg.appName;
18011806
message["loggerName"] = msg.loggerName;
1807+
message["loggerSubName"] = msg.loggerSubName;
18021808
message["function"] = msg.function;
18031809
message["line"] = QString::number(msg.line);
18041810
message["fileName"] = msg.fileName;

libsrc/api/JsonCB.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ void JsonCB::resetSubscriptions()
156156

157157
void JsonCB::setSubscriptionsTo(Hyperion* hyperion)
158158
{
159+
assert(hyperion);
159160
//std::cout << "JsonCB::setSubscriptions for instance [" << static_cast<int>(hyperion->getInstanceIndex()) << "] " << std::endl;
160161

161162
// get current subs
@@ -166,7 +167,7 @@ void JsonCB::setSubscriptionsTo(Hyperion* hyperion)
166167

167168
// update pointer
168169
_hyperion = hyperion;
169-
_componentRegister = &_hyperion->getComponentRegister();
170+
_componentRegister = _hyperion->getComponentRegister();
170171
_prioMuxer = _hyperion->getMuxerInstance();
171172

172173
// re-apply subs

libsrc/blackborder/BlackBorderProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void BlackBorderProcessor::handleSettingsUpdate(settings::type type, const QJson
6969
_detector = new BlackBorderDetector(newThreshold);
7070
}
7171

72-
Debug(Logger::getInstance("BLACKBORDER"), "Set mode to: %s", QSTRING_CSTR(_detectionMode));
72+
Debug(Logger::getInstance("BLACKBORDER", "I"+QString::number(_hyperion->getInstanceIndex())), "Set mode to: %s", QSTRING_CSTR(_detectionMode));
7373

7474
// eval the comp state
7575
handleCompStateChangeRequest(hyperion::COMP_BLACKBORDER, obj["enable"].toBool(true));

libsrc/effectengine/EffectEngine.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
EffectEngine::EffectEngine(Hyperion * hyperion)
2121
: _hyperion(hyperion)
22-
, _log(Logger::getInstance("EFFECTENGINE"))
22+
, _log(nullptr)
2323
, _effectFileHandler(EffectFileHandler::getInstance())
2424
{
25+
QString subComponent = hyperion->property("instance").toString();
26+
_log= Logger::getInstance("EFFECTENGINE", subComponent);
27+
2528
Q_INIT_RESOURCE(EffectEngine);
2629
qRegisterMetaType<hyperion::Components>("hyperion::Components");
2730

0 commit comments

Comments
 (0)