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
This commit is contained in:
redPanther 2016-11-26 22:46:16 +01:00 committed by GitHub
parent 73406c982b
commit 1b62d9d717
13 changed files with 265 additions and 159 deletions

View File

@ -1,79 +1,80 @@
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header"><i class="fa fa-dashboard fa-fw"></i><span lang="en" data-lang-token="main_menu_dashboard_token">Dashboard</span></h2>
<div class="introd">
<h4 lang="en" data-lang-token="dashboard_label_intro">The dashboard give you a quick overview about the status of Hyperion and show you the latest news of the Hyperion Blog.</h4>
</div>
<hr>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-info-circle fa-fw"></i>
<span lang="en" data-lang-token="dashboard_infobox_label_title">Information</span>
</div>
<div class="panel-body">
<table class="table borderless">
<tbody>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_currenthyp">Your Hyperion version:</td>
<td id="currentversion">unknown</td>
</tr>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_latesthyp">Latest version:</td>
<td id="latestversion">unknown</td>
</tr>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_leddevice">LED type:</td>
<td id="dash_leddevice">unknown</td>
</tr>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_device">Device:</td>
<td id="dash_systeminfo"></td>
</tr>
</tbody>
</table>
<hr>
<span id="versioninforesult"></span>
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-eye fa-fw"></i>
<span lang="en" data-lang-token="dashboard_componentbox_label_title">Components status</span>
</div>
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th lang="en" data-lang-token="dashboard_componentbox_label_comp">Component</th>
<th lang="en" data-lang-token="dashboard_componentbox_label_status">Status</th>
</tr>
</thead>
<tbody id="tab_components">
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-5">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-newspaper-o fa-fw"></i>
<span lang="en" data-lang-token="dashboard_newsbox_label_title">Latest blog posts</span>
</div>
<div class="panel-body">
</div>
</div>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="container-fluid" id="content_dashboard">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header"><i class="fa fa-dashboard fa-fw"></i><span lang="en" data-lang-token="main_menu_dashboard_token">Dashboard</span></h2>
<div class="introd">
<h4 lang="en" data-lang-token="dashboard_label_intro">The dashboard give you a quick overview about the status of Hyperion and show you the latest news of the Hyperion Blog.</h4>
</div>
<!-- /.container-fluid -->
<hr>
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-info-circle fa-fw"></i>
<span lang="en" data-lang-token="dashboard_infobox_label_title">Information</span>
</div>
<div class="panel-body">
<table class="table borderless">
<tbody>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_currenthyp">Your Hyperion version:</td>
<td id="currentversion">unknown</td>
</tr>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_latesthyp">Latest version:</td>
<td id="latestversion">unknown</td>
</tr>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_leddevice">LED type:</td>
<td id="dash_leddevice">unknown</td>
</tr>
<tr>
<td lang="en" data-lang-token="dashboard_infobox_label_device">Device:</td>
<td id="dash_systeminfo"></td>
</tr>
</tbody>
</table>
<hr>
<span id="versioninforesult"></span>
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-eye fa-fw"></i>
<span lang="en" data-lang-token="dashboard_componentbox_label_title">Components status</span>
</div>
<div class="panel-body">
<table class="table">
<thead>
<tr>
<th lang="en" data-lang-token="dashboard_componentbox_label_comp">Component</th>
<th lang="en" data-lang-token="dashboard_componentbox_label_status">Status</th>
</tr>
</thead>
<tbody id="tab_components">
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-5">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-newspaper-o fa-fw"></i>
<span lang="en" data-lang-token="dashboard_newsbox_label_title">Latest blog posts</span>
</div>
<div class="panel-body">
</div>
</div>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->

View File

@ -0,0 +1,19 @@
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header"><i class="fa fa-play-circle-o fa-fw"></i><span lang="en" data-lang-token="conf_kodi_label_title">Log Messages</span></h2>
<div class="introd">
<h4 lang="en" data-lang-token="conf_logging_label_intro">log messages.</h4>
</div>
<hr />
<div class="col-lg-12">
<div id="logmessages" style="white-space:pre">
</div>
</div>
</div>
</div>
</div>
<script src="/js/content_logging.js"></script>

View File

@ -220,6 +220,7 @@
<li>
<a class="inactive"><i class="fa fa-industry fa-fw"></i><span lang="en" data-lang-token="main_menu_system_token">System</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li> <a class="inactive" id="load_logging"><i class="fa fa-download fa-fw"></i><span lang="en" data-lang-token="main_menu_logging_token">Events</span></a> </li>
<li> <a class="inactive" id="load_update"><i class="fa fa-download fa-fw"></i><span lang="en" data-lang-token="main_menu_update_token">Update</span></a> </li>
</ul>
</li>

View File

@ -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<components.length;idx++)
if ($("#content_dashboard").length > 0)
{
console.log()
components_html += '<tr><td lang="en" data-lang-token="general_comp_'+components[idx].name+'">'+(components[idx].title)+'</td><td><i class="fa fa-circle component-'+(components[idx].enabled?"on":"off")+'"></i></td></tr>';
$('#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; idx<components.length;idx++)
{
$('#versioninforesult').html('<div lang="en" data-lang-token="dashboard_infobox_message_updatewarning" style="margin:0px;" class="alert alert-warning">A newer version of Hyperion is available!</div>');
components_html += '<tr><td lang="en" data-lang-token="general_comp_'+components[idx].name+'">'+(components[idx].title)+'</td><td><i class="fa fa-circle component-'+(components[idx].enabled?"on":"off")+'"></i></td></tr>';
}
else
{
$('#versioninforesult').html('<div lang="en" data-lang-token="dashboard_infobox_message_updatesuccess" style="margin:0px;" class="alert alert-success">You run the latest version of Hyperion.</div>');
}
});
$("#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('<div lang="en" data-lang-token="dashboard_infobox_message_updatewarning" style="margin:0px;" class="alert alert-warning">A newer version of Hyperion is available!</div>');
}
else
{
$('#versioninforesult').html('<div lang="en" data-lang-token="dashboard_infobox_message_updatesuccess" style="margin:0px;" class="alert alert-success">You run the latest version of Hyperion.</div>');
}
});
}
if ($("#logmessages").length == 0)
{
requestLoggingStop();
}
$("#loading_overlay").removeClass("overlay");
$("#main-nav").show('slide', {direction: 'left'}, 1000);

View File

@ -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<messages.length; idx++)
{
msg = messages[idx];
$("#logmessages").html($("#logmessages").html()+"\n"+msg);
}
}
});
}
});

View File

@ -36,6 +36,8 @@ var hyperion = {};
var wsTan = 1;
var cronId = 0;
var ledStreamActive=false;
var loggingStreamActive=false;
var loggingHandlerInstalled = false;
var watchdog = 0;
//
@ -215,5 +217,16 @@ function requestTestEffect(effectName,effectPy,effectArgs) {
}
function requestDeleteEffect(effectName) {
websocket.send('{"command":"delete-effect","name":"'+effectName+'"}');
websocket.send('{"command":"delete-effect", "tan":'+wsTan+',"name":"'+effectName+'"}');
}
function requestLoggingStart() {
loggingStreamActive=true;
websocket.send('{"command":"logging", "tan":'+wsTan+',"subcommand":"start"}');
}
function requestLoggingStop() {
loggingStreamActive=false;
websocket.send('{"command":"logging", "tan":'+wsTan+',"subcommand":"stop"}');
}

View File

@ -54,7 +54,6 @@ public:
static void deleteInstance(std::string name="");
static void setLogLevel(LogLevel level,std::string name="");
static LogLevel getLogLevel(std::string name="");
static QVector<Logger::T_LOG_MESSAGE>* 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<std::string,Logger*> *LoggerMap;
static LogLevel GLOBAL_MIN_LOG_LEVEL;
static QVector<T_LOG_MESSAGE> *GlobalLogMessageBuffer;
static QVector<T_LOG_MESSAGE> *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<Logger::T_LOG_MESSAGE>* 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<Logger::T_LOG_MESSAGE> _logMessageBuffer;
const int _loggerMaxMsgBufferSize;
};

View File

@ -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>("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<Logger::T_LOG_MESSAGE>* logBuffer = Logger::getGlobalLogMessageBuffer();
QVector<Logger::T_LOG_MESSAGE>* logBuffer = LoggerManager::getInstance()->getLogMessageBuffer();
for(int i=0; i<logBuffer->length(); 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);
}

View File

@ -17,5 +17,6 @@
<file alias="schema-config">schema/schema-config.json</file>
<file alias="schema-componentstate">schema/schema-componentstate.json</file>
<file alias="schema-ledcolors">schema/schema-ledcolors.json</file>
<file alias="schema-logging">schema/schema-logging.json</file>
</qresource>
</RCC>

View File

@ -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
}

View File

@ -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"]
}
}
}

View File

@ -15,9 +15,7 @@ static const int loggerMaxMsgBufferSize = 50;
std::map<std::string,Logger*> *Logger::LoggerMap = nullptr;
Logger::LogLevel Logger::GLOBAL_MIN_LOG_LEVEL = Logger::UNSET;
QVector<Logger::T_LOG_MESSAGE> *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<std::string,Logger*>(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<Logger::T_LOG_MESSAGE>;
}
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;
}

View File

@ -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