mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
global logbuffer (#297)
* - implement a global logbuffer - providerrs232 reduce log spam * logger add signal and start json push * implement logger notifier ... need some cleanup
This commit is contained in:
@@ -47,9 +47,11 @@ 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()));
|
||||
@@ -57,6 +59,9 @@ JsonClientConnection::JsonClientConnection(QTcpSocket *socket)
|
||||
|
||||
_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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -306,6 +311,8 @@ void JsonClientConnection::handleMessage(const QString& messageString)
|
||||
handleComponentStateCommand(message, command, tan);
|
||||
else if (command == "ledcolors")
|
||||
handleLedColorsCommand(message, command, tan);
|
||||
else if (command == "logging")
|
||||
handleLoggingCommand(message, command, tan);
|
||||
else
|
||||
handleNotImplemented();
|
||||
}
|
||||
@@ -1204,6 +1211,55 @@ void JsonClientConnection::handleLedColorsCommand(const QJsonObject& message, co
|
||||
sendSuccessReply(command+"-"+subcommand,tan);
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleLoggingCommand(const QJsonObject& message, const QString &command, const int tan)
|
||||
{
|
||||
// create result
|
||||
QString subcommand = message["subcommand"].toString("");
|
||||
_streaming_logging_reply["success"] = true;
|
||||
_streaming_logging_reply["command"] = command;
|
||||
_streaming_logging_reply["tan"] = tan;
|
||||
|
||||
if (subcommand == "start")
|
||||
{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
else if (subcommand == "stop")
|
||||
{
|
||||
if (_streaming_logging_activated)
|
||||
{
|
||||
disconnect(_log, SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, 0);
|
||||
_streaming_logging_activated = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("unknown subcommand",command,tan);
|
||||
return;
|
||||
}
|
||||
|
||||
sendSuccessReply(command+"-"+subcommand,tan);
|
||||
}
|
||||
|
||||
void JsonClientConnection::incommingLogMessage(Logger::T_LOG_MESSAGE msg)
|
||||
{
|
||||
if (!_streaming_logging_activated)
|
||||
{
|
||||
_streaming_logging_activated = true;
|
||||
QVector<Logger::T_LOG_MESSAGE>* logBuffer = Logger::getGlobalLogMessageBuffer();
|
||||
for(int i=0; i<logBuffer->length(); i++)
|
||||
{
|
||||
std::cout << "------- " << logBuffer->at(i).message.toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "------- " << msg.message.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void JsonClientConnection::handleNotImplemented()
|
||||
{
|
||||
sendErrorReply("Command not implemented");
|
||||
|
Reference in New Issue
Block a user