IXCobraMetricsThreadedPublisher.cpp uses a lambda to log instead of std::cerr
This commit is contained in:
		| @@ -29,6 +29,8 @@ add_executable(ws | |||||||
|   ../third_party/jsoncpp/jsoncpp.cpp |   ../third_party/jsoncpp/jsoncpp.cpp | ||||||
|   ../third_party/statsd-client-cpp/src/statsd_client.cpp |   ../third_party/statsd-client-cpp/src/statsd_client.cpp | ||||||
|  |  | ||||||
|  |   ixcore/utils/IXCoreLogger.cpp | ||||||
|  |  | ||||||
|   ixcrypto/IXBase64.cpp |   ixcrypto/IXBase64.cpp | ||||||
|   ixcrypto/IXHash.cpp |   ixcrypto/IXHash.cpp | ||||||
|   ixcrypto/IXUuid.cpp |   ixcrypto/IXUuid.cpp | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ | |||||||
|  |  | ||||||
| #include "IXCobraMetricsThreadedPublisher.h" | #include "IXCobraMetricsThreadedPublisher.h" | ||||||
| #include <ixwebsocket/IXSetThreadName.h> | #include <ixwebsocket/IXSetThreadName.h> | ||||||
|  | #include <ixcore/utils/IXCoreLogger.h> | ||||||
|  |  | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
| #include <stdexcept> | #include <stdexcept> | ||||||
| @@ -58,7 +59,7 @@ namespace ix | |||||||
|                     ss << "Unsubscribed through subscription id: " << subscriptionId; |                     ss << "Unsubscribed through subscription id: " << subscriptionId; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 std::cerr << ss.str() << std::endl; |                 ix::IXCoreLogger::Log(ss.str().c_str()); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								ws/ixcore/utils/IXCoreLogger.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								ws/ixcore/utils/IXCoreLogger.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										22
									
								
								ws/ixcore/utils/IXCoreLogger.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								ws/ixcore/utils/IXCoreLogger.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | #pragma once | ||||||
|  | #include <functional> | ||||||
|  |  | ||||||
|  | namespace ix | ||||||
|  | { | ||||||
|  |  | ||||||
|  | class IXCoreLogger | ||||||
|  | { | ||||||
|  | public: | ||||||
|  |     using LogFunc = std::function<void(const char*)>; | ||||||
|  |     static void Log(const char* msg); | ||||||
|  |  | ||||||
|  |     static void setLogFunction(LogFunc& func) { | ||||||
|  |         _currentLogger = func; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | private: | ||||||
|  |     static LogFunc _currentLogger; | ||||||
|  |  | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | } // ix | ||||||
| @@ -22,11 +22,18 @@ | |||||||
| #include <cli11/CLI11.hpp> | #include <cli11/CLI11.hpp> | ||||||
| #include <ixwebsocket/IXSocket.h> | #include <ixwebsocket/IXSocket.h> | ||||||
| #include <ixwebsocket/IXNetSystem.h> | #include <ixwebsocket/IXNetSystem.h> | ||||||
|  | #include <ixcore/utils/IXCoreLogger.h> | ||||||
|  |  | ||||||
| int main(int argc, char** argv) | int main(int argc, char** argv) | ||||||
| { | { | ||||||
|     ix::initNetSystem(); |     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"}; |     CLI::App app{"ws is a websocket tool"}; | ||||||
|     app.require_subcommand(); |     app.require_subcommand(); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user