浏览代码

Integrate plog

Murat Dogan 5 年之前
父节点
当前提交
92f08948d3
共有 7 个文件被更改,包括 24 次插入2 次删除
  1. 3 0
      .gitmodules
  2. 4 1
      CMakeLists.txt
  3. 1 0
      deps/plog
  4. 4 0
      include/rtc/configuration.hpp
  5. 1 0
      include/rtc/include.hpp
  6. 7 0
      src/configuration.cpp
  7. 4 1
      test/main.cpp

+ 3 - 0
.gitmodules

@@ -1,3 +1,6 @@
 [submodule "usrsctp"]
 	path = deps/usrsctp
 	url = https://github.com/sctplab/usrsctp.git
+[submodule "deps/plog"]
+	path = deps/plog
+	url = https://github.com/SergiusTheBest/plog

+ 4 - 1
CMakeLists.txt

@@ -7,7 +7,7 @@ project (libdatachannel
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
 
-set(LIBDATACHANNEL_SOURCES
+set(LIBDATACHANNEL_SOURCES	
 	${CMAKE_CURRENT_SOURCE_DIR}/src/candidate.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/certificate.cpp
 	${CMAKE_CURRENT_SOURCE_DIR}/src/channel.cpp
@@ -62,6 +62,7 @@ set_target_properties(datachannel PROPERTIES
 target_include_directories(datachannel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
 target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
 target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
+target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/plog/include)
 target_link_libraries(datachannel usrsctp-static LibNice::LibNice)
 
 add_library(datachannel-static STATIC EXCLUDE_FROM_ALL ${LIBDATACHANNEL_SOURCES})
@@ -72,6 +73,7 @@ set_target_properties(datachannel-static PROPERTIES
 target_include_directories(datachannel-static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
 target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/rtc)
 target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
+target_include_directories(datachannel-static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/plog/include)
 target_link_libraries(datachannel-static usrsctp-static LibNice::LibNice)
 
 if (USE_GNUTLS)
@@ -104,5 +106,6 @@ set_target_properties(tests PROPERTIES
 	VERSION ${PROJECT_VERSION}
 	CXX_STANDARD 17)
 
+target_include_directories(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/plog/include)
 target_link_libraries(tests datachannel)
 

+ 1 - 0
deps/plog

@@ -0,0 +1 @@
+Subproject commit 293164468998b2ff8d4d13684c065f736ec68fb4

+ 4 - 0
include/rtc/configuration.hpp

@@ -47,6 +47,10 @@ struct IceServer {
 };
 
 struct Configuration {
+	enum class LogLevel { none, fatal, error, warning, info, debug, verbose };
+
+	Configuration(const LogLevel logLevel_ = LogLevel::error);
+
 	std::vector<IceServer> iceServers;
 	bool enableIceTcp = false;
 	uint16_t portRangeBegin = 1024;

+ 1 - 0
include/rtc/include.hpp

@@ -26,6 +26,7 @@
 #include <optional>
 #include <string>
 #include <vector>
+#include <plog/Log.h>
 
 namespace rtc {
 

+ 7 - 0
src/configuration.cpp

@@ -17,6 +17,7 @@
  */
 
 #include "configuration.hpp"
+#include <plog/Appenders/ColorConsoleAppender.h>
 
 namespace rtc {
 
@@ -43,4 +44,10 @@ IceServer::IceServer(const string &hostname_, const string &service_, string use
     : hostname(hostname_), service(service_), type(Type::Turn), username(username_),
       password(password_), relayType(relayType_) {}
 
+Configuration::Configuration(const LogLevel logLevel_) {
+	static plog::ColorConsoleAppender<plog::TxtFormatter> consoleAppender;
+	plog::init(static_cast<plog::Severity>(logLevel_), &consoleAppender);
+	LOGD << "Logger Initialized";
+}
+
 } // namespace rtc

+ 4 - 1
test/main.cpp

@@ -29,12 +29,15 @@ using namespace std;
 template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> ptr) { return ptr; }
 
 int main(int argc, char **argv) {
+	// For debug messages
+	// rtc::Configuration config(Configuration::LogLevel::debug)
 	rtc::Configuration config;
+
 	// config.iceServers.emplace_back("stun.l.google.com:19302");
 	// config.enableIceTcp = true;
 
 	// Add TURN Server Example
-	// IceServer turnServer("TURN_SERVER_URL", "PORT_NO", "USERNAME", "PASSWORD", 
+	// IceServer turnServer("TURN_SERVER_URL", "PORT_NO", "USERNAME", "PASSWORD",
 	//							IceServer::RelayType::TurnTls);
 	// config.iceServers.push_back(turnServer);