diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f4502e..4d190d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -project(owanalytics VERSION 2.5.0) +project(owanalytics VERSION 2.6.0) set(CMAKE_CXX_STANDARD 17) diff --git a/build b/build index e440e5c..56a6051 100644 --- a/build +++ b/build @@ -1 +1 @@ -3 \ No newline at end of file +1 \ No newline at end of file diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 795d5bb..03e3e36 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -70,6 +70,7 @@ using namespace std::chrono_literals; #include "Poco/FileChannel.h" #include "Poco/SimpleFileChannel.h" #include "Poco/Util/PropertyFileConfiguration.h" +#include "Poco/SplitterChannel.h" #include "cppkafka/cppkafka.h" @@ -2846,8 +2847,86 @@ namespace OpenWifi { return 0; } - class RESTAPI_IntServer : public SubSystemServer { + class LogMuxer : public Poco::Channel { + public: + + inline std::string getProperty( const std::string &p ) const final { + return ""; + } + + inline void close() final { + } + + inline void open() final { + } + + inline static std::string to_string(Poco::Message::Priority p) { + switch(p) { + case Poco::Message::PRIO_INFORMATION: return "information"; + case Poco::Message::PRIO_CRITICAL: return "critical"; + case Poco::Message::PRIO_DEBUG: return "debug"; + case Poco::Message::PRIO_ERROR: return "error"; + case Poco::Message::PRIO_FATAL: return "level"; + case Poco::Message::PRIO_NOTICE: return "notice"; + case Poco::Message::PRIO_TRACE: return "trace"; + case Poco::Message::PRIO_WARNING: return "warning"; + default: return "none"; + } + } + + inline void log(const Poco::Message &m) final { + if(Enabled_) { + /* + nlohmann::json log_msg; + log_msg["msg"] = m.getText(); + log_msg["level"] = to_string(m.getPriority()); + log_msg["timestamp"] = Poco::DateTimeFormatter::format(m.getTime(), Poco::DateTimeFormat::ISO8601_FORMAT); + log_msg["source"] = m.getSource(); + log_msg["thread_name"] = m.getThread(); + log_msg["thread_id"] = m.getTid(); + + std::cout << log_msg << std::endl; + */ + std::lock_guard G(Mutex_); + std::vector Remove; + for(const auto &[Id,CallBack]:CallBacks_) { + try { + CallBack(m); + } catch (...) { + Remove.push_back(Id); + } + } + for(const auto &i:Remove) + CallBacks_.erase(i); + } + } + + inline void setProperty(const std::string &name, const std::string &value) final { + + } + + inline static auto instance() { + static auto instance_ = new LogMuxer; + return instance_; + } + inline void Enable(bool enable) { Enabled_ = enable; } + typedef std::function logmuxer_callback_func_t; + inline void RegisterCallback(const logmuxer_callback_func_t & R, uint64_t &Id) { + std::lock_guard G(Mutex_); + Id = CallBackId_++; + CallBacks_[Id] = R; + } + private: + std::recursive_mutex Mutex_; + std::map CallBacks_; + inline static uint64_t CallBackId_=1; + bool Enabled_ = false; + }; + inline auto LogMuxer() { return LogMuxer::instance(); } + + + class RESTAPI_IntServer : public SubSystemServer { public: static auto instance() { static auto instance_ = new RESTAPI_IntServer; @@ -3258,11 +3337,15 @@ namespace OpenWifi { FileChannel->setProperty("rotation", "10 M"); FileChannel->setProperty("archive", "timestamp"); FileChannel->setProperty("path", LoggingLocation); - Poco::AutoPtr Async(new Poco::AsyncChannel(FileChannel)); - Poco::AutoPtr Formatter(new Poco::PatternFormatter); + Poco::AutoPtr Async_File(new Poco::AsyncChannel(FileChannel)); + Poco::AutoPtr Async_Muxer(new Poco::AsyncChannel(LogMuxer())); + Poco::AutoPtr Splitter(new Poco::SplitterChannel); + Splitter->addChannel(Async_File); + Splitter->addChannel(Async_Muxer); + Poco::AutoPtr Formatter(new Poco::PatternFormatter); Formatter->setProperty("pattern", LoggingFormat); Poco::AutoPtr FormattingChannel( - new Poco::FormattingChannel(Formatter, Async)); + new Poco::FormattingChannel(Formatter, Splitter)); Poco::Logger::root().setChannel(FormattingChannel); } auto Level = Poco::Logger::parseLevel(MicroService::instance().ConfigGetString("logging.level", "debug"));