From c13c39e42beb490741b29f24aee97069c89d42c3 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 7 Apr 2021 19:37:55 +0200 Subject: [PATCH] move logging into logging folder - so this special log files are also easy accessable with docker - by the way update default logging channels to use FileChannel and compress and archive rotated logfiles - use logging system from Poco rather than raw FILE for hedera transaction logging --- login_server/src/cpp/Gradido_LoginServer.cpp | 19 +++++++++++++++++- login_server/src/cpp/Gradido_LoginServer.h | 1 + login_server/src/cpp/lib/JsonRequest.cpp | 21 +++++++++++++++----- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/login_server/src/cpp/Gradido_LoginServer.cpp b/login_server/src/cpp/Gradido_LoginServer.cpp index 5d3f09f03..af975f98e 100644 --- a/login_server/src/cpp/Gradido_LoginServer.cpp +++ b/login_server/src/cpp/Gradido_LoginServer.cpp @@ -24,6 +24,7 @@ #include "Poco/Path.h" #include "Poco/AsyncChannel.h" #include "Poco/SimpleFileChannel.h" +#include "Poco/FileChannel.h" #include "Poco/ConsoleChannel.h" #include "Poco/SplitterChannel.h" #include "MySQL/Poco/Connector.h" @@ -93,8 +94,10 @@ void Gradido_LoginServer::displayHelp() void Gradido_LoginServer::createConsoleFileAsyncLogger(std::string name, std::string filePath) { Poco::AutoPtr logConsoleChannel(new Poco::ConsoleChannel); - Poco::AutoPtr logFileChannel(new Poco::SimpleFileChannel(filePath)); + Poco::AutoPtr logFileChannel(new Poco::FileChannel(filePath)); logFileChannel->setProperty("rotation", "500 K"); + logFileChannel->setProperty("compress", "true"); + logFileChannel->setProperty("archive", "timestamp"); Poco::AutoPtr logSplitter(new Poco::SplitterChannel); logSplitter->addChannel(logConsoleChannel); logSplitter->addChannel(logFileChannel); @@ -106,6 +109,16 @@ void Gradido_LoginServer::createConsoleFileAsyncLogger(std::string name, std::st log.setLevel("information"); } +void Gradido_LoginServer::createFileLogger(std::string name, std::string filePath) +{ + Poco::AutoPtr logFileChannel(new Poco::FileChannel(filePath)); + logFileChannel->setProperty("rotation", "500 K"); + logFileChannel->setProperty("archive", "timestamp"); + Poco::Logger& log = Poco::Logger::get(name); + log.setChannel(logFileChannel); + log.setLevel("information"); +} + int Gradido_LoginServer::main(const std::vector& args) { Profiler usedTime; @@ -141,6 +154,10 @@ int Gradido_LoginServer::main(const std::vector& args) // logging for request handling createConsoleFileAsyncLogger("requestLog", log_Path + "requestLog.txt"); + // logging for hedera request for debugging gradido node + createFileLogger("transactions_log", log_Path + "transactions_log.txt"); + createFileLogger("transactions_log_base64", log_Path + "transactions_log_base64.txt"); + // error logging createConsoleFileAsyncLogger("errorLog", log_Path + "errorLog.txt"); Poco::Logger& errorLog = Poco::Logger::get("errorLog"); diff --git a/login_server/src/cpp/Gradido_LoginServer.h b/login_server/src/cpp/Gradido_LoginServer.h index 0a14d9000..d31f36dbf 100644 --- a/login_server/src/cpp/Gradido_LoginServer.h +++ b/login_server/src/cpp/Gradido_LoginServer.h @@ -33,6 +33,7 @@ protected: int main(const std::vector& args); void createConsoleFileAsyncLogger(std::string name, std::string filePath); + void createFileLogger(std::string name, std::string filePath); private: bool _helpRequested; diff --git a/login_server/src/cpp/lib/JsonRequest.cpp b/login_server/src/cpp/lib/JsonRequest.cpp index ed3448b31..746e8b154 100644 --- a/login_server/src/cpp/lib/JsonRequest.cpp +++ b/login_server/src/cpp/lib/JsonRequest.cpp @@ -38,15 +38,21 @@ JsonRequestReturn JsonRequest::request(const char* methodName, const Poco::JSON: try { Profiler phpRequestTime; - Poco::Net::HTTPSClientSession httpsClientSession(mServerHost, mServerPort); + Poco::SharedPtr clientSession; + if (mServerPort == 443) { + clientSession = new Poco::Net::HTTPSClientSession(mServerHost, mServerPort); + } + else { + clientSession = new Poco::Net::HTTPClientSession(mServerHost, mServerPort); + } Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/JsonRequestHandler"); request.setChunkedTransferEncoding(true); - std::ostream& request_stream = httpsClientSession.sendRequest(request); + std::ostream& request_stream = clientSession->sendRequest(request); requestJson.stringify(request_stream); Poco::Net::HTTPResponse response; - std::istream& response_stream = httpsClientSession.receiveResponse(response); + std::istream& response_stream = clientSession->receiveResponse(response); // debugging answer @@ -66,8 +72,13 @@ JsonRequestReturn JsonRequest::request(const char* methodName, const Poco::JSON: } catch (Poco::Exception& ex) { addError(new ParamError(functionName, "error parsing request answer", ex.displayText().data())); - - std::string fileName = "response_"; + std::string dateTimeString = Poco::DateTimeFormatter::format(Poco::DateTime(), "%d%m%yT%H%M%S"); + std::string log_Path = "/var/log/grd_login/"; + //#ifdef _WIN32 +#if defined(_WIN32) || defined(_WIN64) + log_Path = "./"; +#endif + std::string fileName = log_Path + dateTimeString + "_response_"; fileName += methodName; fileName += ".html";