diff --git a/ws/CMakeLists.txt b/ws/CMakeLists.txt index fff630ab..68605528 100644 --- a/ws/CMakeLists.txt +++ b/ws/CMakeLists.txt @@ -29,6 +29,8 @@ add_executable(ws ../third_party/jsoncpp/jsoncpp.cpp ../third_party/statsd-client-cpp/src/statsd_client.cpp + ixcore/utils/IXCoreLogger.cpp + ixcrypto/IXBase64.cpp ixcrypto/IXHash.cpp ixcrypto/IXUuid.cpp diff --git a/ws/ixcobra/IXCobraMetricsThreadedPublisher.cpp b/ws/ixcobra/IXCobraMetricsThreadedPublisher.cpp index 4a400e48..bf160cef 100644 --- a/ws/ixcobra/IXCobraMetricsThreadedPublisher.cpp +++ b/ws/ixcobra/IXCobraMetricsThreadedPublisher.cpp @@ -6,6 +6,7 @@ #include "IXCobraMetricsThreadedPublisher.h" #include +#include #include #include @@ -58,7 +59,7 @@ namespace ix ss << "Unsubscribed through subscription id: " << subscriptionId; } - std::cerr << ss.str() << std::endl; + ix::IXCoreLogger::Log(ss.str().c_str()); }); } diff --git a/ws/ixcore/utils/IXCoreLogger.cpp b/ws/ixcore/utils/IXCoreLogger.cpp new file mode 100644 index 00000000..427b375e --- /dev/null +++ b/ws/ixcore/utils/IXCoreLogger.cpp @@ -0,0 +1,14 @@ +#include "ixcore/utils/IXCoreLogger.h" + + +namespace ix +{ +// Default do nothing logger +IXCoreLogger::LogFunc IXCoreLogger::_currentLogger = [](const char* msg){}; + +void IXCoreLogger::Log(const char* msg) +{ + _currentLogger(msg); +} + +} // ix diff --git a/ws/ixcore/utils/IXCoreLogger.h b/ws/ixcore/utils/IXCoreLogger.h new file mode 100644 index 00000000..ae263fce --- /dev/null +++ b/ws/ixcore/utils/IXCoreLogger.h @@ -0,0 +1,22 @@ +#pragma once +#include + +namespace ix +{ + +class IXCoreLogger +{ +public: + using LogFunc = std::function; + static void Log(const char* msg); + + static void setLogFunction(LogFunc& func) { + _currentLogger = func; + } + +private: + static LogFunc _currentLogger; + +}; + +} // ix diff --git a/ws/ws.cpp b/ws/ws.cpp index 105a76e9..b520cd51 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -22,11 +22,18 @@ #include #include #include +#include int main(int argc, char** argv) { ix::initNetSystem(); + ix::IXCoreLogger::LogFunc logFunc = [](const char* msg) + { + std::cout << msg << std::endl; + }; + ix::IXCoreLogger::setLogFunction(logFunc); + CLI::App app{"ws is a websocket tool"}; app.require_subcommand();