mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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>
|
||||
|
28
libsrc/jsonserver/schema/schema-logging.json
Normal file
28
libsrc/jsonserver/schema/schema-logging.json
Normal 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
|
||||
}
|
||||
|
@@ -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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user