From 1b62d9d717aac13a7128de909360ba10e5ecc1f3 Mon Sep 17 00:00:00 2001 From: redPanther Date: Sat, 26 Nov 2016 22:46:16 +0100 Subject: [PATCH] Logbuffer (#298) * - implement a global logbuffer - providerrs232 reduce log spam * logger add signal and start json push * implement logger notifier ... need some cleanup * imlement logview in webui - the layout stuff is basic atm and needs some tuning --- assets/webconfig/content/dashboard.html | 155 ++++++++++--------- assets/webconfig/content/logging.html | 19 +++ assets/webconfig/index.html | 1 + assets/webconfig/js/content_index.js | 64 +++++--- assets/webconfig/js/content_logging.js | 24 +++ assets/webconfig/js/hyperion.js | 15 +- include/utils/Logger.h | 21 +-- libsrc/jsonserver/JsonClientConnection.cpp | 34 ++-- libsrc/jsonserver/JsonSchemas.qrc | 1 + libsrc/jsonserver/schema/schema-logging.json | 28 ++++ libsrc/jsonserver/schema/schema.json | 2 +- libsrc/utils/Logger.cpp | 40 ++--- src/hyperion-remote/JsonConnection.h | 20 +-- 13 files changed, 265 insertions(+), 159 deletions(-) create mode 100644 assets/webconfig/content/logging.html create mode 100644 assets/webconfig/js/content_logging.js create mode 100644 libsrc/jsonserver/schema/schema-logging.json diff --git a/assets/webconfig/content/dashboard.html b/assets/webconfig/content/dashboard.html index 7eef11df..b1ca9bca 100644 --- a/assets/webconfig/content/dashboard.html +++ b/assets/webconfig/content/dashboard.html @@ -1,79 +1,80 @@ -
-
-
- -
-

The dashboard give you a quick overview about the status of Hyperion and show you the latest news of the Hyperion Blog.

-
-
-
-
-
- - Information -
-
- - - - - - - - - - - - - - - - - - - -
Your Hyperion version:unknown
Latest version:unknown
LED type:unknown
Device:
-
- -
-
-
-
-
-
- - Components status -
-
- - - - - - - - - -
ComponentStatus
-
-
-
-
-
-
- - Latest blog posts -
-
-
-
-
- -
- -
- +
+
+
+ +
+

The dashboard give you a quick overview about the status of Hyperion and show you the latest news of the Hyperion Blog.

- - +
+
+
+
+ + Information +
+
+ + + + + + + + + + + + + + + + + + + +
Your Hyperion version:unknown
Latest version:unknown
LED type:unknown
Device:
+
+ +
+
+
+
+
+
+ + Components status +
+
+ + + + + + + + + +
ComponentStatus
+
+
+
+
+
+
+ + Latest blog posts +
+
+ +
+
+
+ +
+ +
+ +
+ + diff --git a/assets/webconfig/content/logging.html b/assets/webconfig/content/logging.html new file mode 100644 index 00000000..cdcfc5b6 --- /dev/null +++ b/assets/webconfig/content/logging.html @@ -0,0 +1,19 @@ +
+
+
+ +
+

log messages.

+
+
+ +
+
+
+
+ +
+
+
+ + diff --git a/assets/webconfig/index.html b/assets/webconfig/index.html index 86f52f61..ae2a7118 100644 --- a/assets/webconfig/index.html +++ b/assets/webconfig/index.html @@ -220,6 +220,7 @@
  • System
  • diff --git a/assets/webconfig/js/content_index.js b/assets/webconfig/js/content_index.js index 82d1a1e9..a4a5a617 100644 --- a/assets/webconfig/js/content_index.js +++ b/assets/webconfig/js/content_index.js @@ -15,6 +15,7 @@ $(document).ready( function() { bindNavToContent("#load_confColors","colors",false); bindNavToContent("#load_confNetwork","network",false); bindNavToContent("#load_effectsconfig","effects_configurator",false); + bindNavToContent("#load_logging","logging",false); //Change all Checkboxes to Switches @@ -32,37 +33,54 @@ $(document).ready( function() { // get active led device var leddevice = parsedServerInfoJSON.info.ledDevices.active; - $('#dash_leddevice').html(leddevice); + if ($("#content_dashboard").length > 0) + { + $('#dash_leddevice').html(leddevice); + } + // get host var hostname = parsedServerInfoJSON.info.hostname; - $('#dash_systeminfo').html(hostname+':'+hyperionport); - - var components = parsedServerInfoJSON.info.components; - components_html = ""; - for ( idx=0; idx 0) { - console.log() - components_html += ''+(components[idx].title)+''; + $('#dash_systeminfo').html(hostname+':'+hyperionport); } - $("#tab_components").html(components_html); - $.get( "https://raw.githubusercontent.com/hyperion-project/hyperion.ng/master/version.json", function( data ) { - parsedUpdateJSON = JSON.parse(data); - latestVersion = parsedUpdateJSON[0].versionnr; - cleanLatestVersion = latestVersion.replace(/\./g, ''); - $('#currentversion').html(' V'+currentVersion); - $('#latestversion').html(' V'+latestVersion); - - if ( cleanCurrentVersion < cleanLatestVersion ) + if ($("#content_dashboard").length > 0) + { + var components = parsedServerInfoJSON.info.components; + components_html = ""; + for ( idx=0; idxA newer version of Hyperion is available!
    '); + components_html += ''+(components[idx].title)+''; } - else - { - $('#versioninforesult').html('
    You run the latest version of Hyperion.
    '); - } - }); + $("#tab_components").html(components_html); + + $.get( "https://raw.githubusercontent.com/hyperion-project/hyperion.ng/master/version.json", function( data ) { + parsedUpdateJSON = JSON.parse(data); + latestVersion = parsedUpdateJSON[0].versionnr; + cleanLatestVersion = latestVersion.replace(/\./g, ''); + + $('#currentversion').html(' V'+currentVersion); + $('#latestversion').html(' V'+latestVersion); + + if ( cleanCurrentVersion < cleanLatestVersion ) + { + $('#versioninforesult').html('
    A newer version of Hyperion is available!
    '); + } + else + { + $('#versioninforesult').html('
    You run the latest version of Hyperion.
    '); + } + }); + } + + if ($("#logmessages").length == 0) + { + requestLoggingStop(); + } + + $("#loading_overlay").removeClass("overlay"); $("#main-nav").show('slide', {direction: 'left'}, 1000); diff --git a/assets/webconfig/js/content_logging.js b/assets/webconfig/js/content_logging.js new file mode 100644 index 00000000..5b39d66d --- /dev/null +++ b/assets/webconfig/js/content_logging.js @@ -0,0 +1,24 @@ + +$(document).ready(function() { + requestLoggingStart(); + if (!loggingHandlerInstalled) + { + loggingHandlerInstalled = true; + $(hyperion).on("cmd-logging-update",function(event){ + if ($("#logmessages").length == 0) + { + requestLoggingStop(); + } + else + { + messages = (event.response.result.messages); + for(var idx=0; idx* getGlobalLogMessageBuffer() { return GlobalLogMessageBuffer; }; void Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...); void setMinLevel(LogLevel level) { _minLevel = level; }; @@ -70,8 +69,6 @@ protected: private: static std::map *LoggerMap; static LogLevel GLOBAL_MIN_LOG_LEVEL; - static QVector *GlobalLogMessageBuffer; - static QVector *LogCallacks; std::string _name; std::string _appname; @@ -80,21 +77,25 @@ private: unsigned int _loggerId; }; -class LoggerNotifier : public QObject + +class LoggerManager : public QObject { Q_OBJECT public: - static LoggerNotifier* getInstance(); + static LoggerManager* getInstance(); + QVector* getLogMessageBuffer() { return &_logMessageBuffer; }; -protected: - LoggerNotifier(); - ~LoggerNotifier(); - - static LoggerNotifier* instance; public slots: void handleNewLogMessage(Logger::T_LOG_MESSAGE); signals: void newLogMessage(Logger::T_LOG_MESSAGE); + +protected: + LoggerManager(); + + static LoggerManager* _instance; + QVector _logMessageBuffer; + const int _loggerMaxMsgBufferSize; }; diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index c854efaf..36e3e776 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -47,21 +47,17 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket) , _hyperion(Hyperion::getInstance()) , _receiveBuffer() , _webSocketHandshakeDone(false) - //, _log(Logger::getInstance("JSONCLIENTCONNECTION")) + , _log(Logger::getInstance("JSONCLIENTCONNECTION")) , _forwarder_enabled(true) , _streaming_logging_activated(false) { - _log = Logger::getInstance("JSONCLIENTCONNECTION"); // connect internal signals and slots connect(_socket, SIGNAL(disconnected()), this, SLOT(socketClosed())); connect(_socket, SIGNAL(readyRead()), this, SLOT(readData())); connect(_hyperion, SIGNAL(componentStateChanged(hyperion::Components,bool)), this, SLOT(componentStateChanged(hyperion::Components,bool))); - + _timer_ledcolors.setSingleShot(false); connect(&_timer_ledcolors, SIGNAL(timeout()), this, SLOT(streamLedcolorsUpdate())); - - //qRegisterMetaType("Logger::T_LOG_MESSAGE"); - connect(LoggerNotifier::getInstance(),SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE))); } @@ -1224,15 +1220,18 @@ void JsonClientConnection::handleLoggingCommand(const QJsonObject& message, cons if (!_streaming_logging_activated) { _streaming_logging_reply["command"] = command+"-update"; - connect(_log,SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE))); + connect(LoggerManager::getInstance(),SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE))); + Debug(_log, "log streaming activated"); // needed to trigger log sending } } else if (subcommand == "stop") { if (_streaming_logging_activated) { - disconnect(_log, SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, 0); + disconnect(LoggerManager::getInstance(), SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, 0); _streaming_logging_activated = false; + Debug(_log, "log streaming deactivated"); + } } else @@ -1246,17 +1245,30 @@ void JsonClientConnection::handleLoggingCommand(const QJsonObject& message, cons void JsonClientConnection::incommingLogMessage(Logger::T_LOG_MESSAGE msg) { + QJsonObject result; + QJsonArray messages; + if (!_streaming_logging_activated) { _streaming_logging_activated = true; - QVector* logBuffer = Logger::getGlobalLogMessageBuffer(); + QVector* logBuffer = LoggerManager::getInstance()->getLogMessageBuffer(); for(int i=0; ilength(); i++) { - std::cout << "------- " << logBuffer->at(i).message.toStdString() << std::endl; + //std::cout << "------- " << logBuffer->at(i).message.toStdString() << std::endl; + messages.append(logBuffer->at(i).message); } } + else + { + //std::cout << "------- " << msg.message.toStdString() << std::endl; + messages.append(msg.message); + } - std::cout << "------- " << msg.message.toStdString() << std::endl; + result["messages"] = messages; + _streaming_logging_reply["result"] = result; + + // send the result + sendMessage(_streaming_logging_reply); } diff --git a/libsrc/jsonserver/JsonSchemas.qrc b/libsrc/jsonserver/JsonSchemas.qrc index 56359910..1e5c00eb 100644 --- a/libsrc/jsonserver/JsonSchemas.qrc +++ b/libsrc/jsonserver/JsonSchemas.qrc @@ -17,5 +17,6 @@ schema/schema-config.json schema/schema-componentstate.json schema/schema-ledcolors.json + schema/schema-logging.json diff --git a/libsrc/jsonserver/schema/schema-logging.json b/libsrc/jsonserver/schema/schema-logging.json new file mode 100644 index 00000000..d9bd7cf7 --- /dev/null +++ b/libsrc/jsonserver/schema/schema-logging.json @@ -0,0 +1,28 @@ +{ + "type":"object", + "required":true, + "properties":{ + "command": { + "type" : "string", + "required" : true, + "enum" : ["logging"] + }, + "tan" : { + "type" : "integer" + }, + "subcommand": { + "type" : "string", + "required" : true, + "enum" : ["stop","start","update"] + }, + "oneshot": { + "type" : "bool" + }, + "interval": { + "type" : "integer" + } + }, + + "additionalProperties": false +} + diff --git a/libsrc/jsonserver/schema/schema.json b/libsrc/jsonserver/schema/schema.json index 566c9904..740f34e7 100644 --- a/libsrc/jsonserver/schema/schema.json +++ b/libsrc/jsonserver/schema/schema.json @@ -5,7 +5,7 @@ "command": { "type" : "string", "required" : true, - "enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate", "ledcolors"] + "enum" : ["color", "image", "effect", "create-effect", "delete-effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment", "sourceselect", "config", "componentstate", "ledcolors", "logging"] } } } diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 271bfbd3..8faa8504 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -15,9 +15,7 @@ static const int loggerMaxMsgBufferSize = 50; std::map *Logger::LoggerMap = nullptr; Logger::LogLevel Logger::GLOBAL_MIN_LOG_LEVEL = Logger::UNSET; -QVector *Logger::GlobalLogMessageBuffer = nullptr; - -LoggerNotifier* LoggerNotifier::instance = nullptr; +LoggerManager* LoggerManager::_instance = nullptr; Logger* Logger::getInstance(std::string name, Logger::LogLevel minLevel) @@ -33,18 +31,13 @@ Logger* Logger::getInstance(std::string name, Logger::LogLevel minLevel) log = new Logger(name,minLevel); LoggerMap->insert(std::pair(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, SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), LoggerNotifier::getInstance(), SLOT(handleNewLogMessage(Logger::T_LOG_MESSAGE))); + connect(log, SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), LoggerManager::getInstance(), SLOT(handleNewLogMessage(Logger::T_LOG_MESSAGE))); } else { log = LoggerMap->at(name); } - if (GlobalLogMessageBuffer == nullptr) - { - GlobalLogMessageBuffer = new QVector; - } - return log; } @@ -158,12 +151,6 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u { location = "<" + logMsg.fileName + ":" + QString::number(line)+":"+ logMsg.function + "()> "; } - - GlobalLogMessageBuffer->append(logMsg); - if (GlobalLogMessageBuffer->length() > loggerMaxMsgBufferSize) - { - GlobalLogMessageBuffer->erase(GlobalLogMessageBuffer->begin()); - } std::cout << "[" << _appname << " " << _name << "] <" @@ -175,25 +162,26 @@ void Logger::Message(LogLevel level, const char* sourceFile, const char* func, u } -LoggerNotifier::LoggerNotifier() +LoggerManager::LoggerManager() : QObject() + , _loggerMaxMsgBufferSize(200) { } -LoggerNotifier::~LoggerNotifier() +void LoggerManager::handleNewLogMessage(Logger::T_LOG_MESSAGE msg) { -} + _logMessageBuffer.append(msg); + if (_logMessageBuffer.length() > _loggerMaxMsgBufferSize) + { + _logMessageBuffer.erase(_logMessageBuffer.begin()); + } - -void LoggerNotifier::handleNewLogMessage(Logger::T_LOG_MESSAGE msg) -{ - //std::cout << "<" << msg.loggerName.toStdString() << "> " << msg.message.toStdString() << std::endl; emit newLogMessage(msg); } -LoggerNotifier* LoggerNotifier::getInstance() +LoggerManager* LoggerManager::getInstance() { - if ( instance == nullptr ) - instance = new LoggerNotifier(); - return instance; + if ( _instance == nullptr ) + _instance = new LoggerManager(); + return _instance; } diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index 4b545fb5..6d0f65a1 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -141,16 +141,16 @@ public: /// @param whitelevel The whitelevel /// void setTransform( - const QString &transformId, - double *saturation, - double *value, - double *saturationL, - double *luminance, - double *luminanceMin, - QColor threshold, - QColor gamma, - QColor blacklevel, - QColor whitelevel); + const QString &transformId, + double *saturation, + double *value, + double *saturationL, + double *luminance, + double *luminanceMin, + QColor threshold, + QColor gamma, + QColor blacklevel, + QColor whitelevel); /// /// Set the color adjustment of the leds