diff --git a/.gitmodules b/.gitmodules index a50af69..2401547 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,6 @@ [submodule "tinyphone-osx/vendor/boost"] path = tinyphone-osx/vendor/boost url = https://github.com/faithfracture/Apple-Boost-BuildScript.git +[submodule "lib/spdlog"] + path = lib/spdlog + url = https://github.com/gabime/spdlog.git diff --git a/lib/spdlog b/lib/spdlog new file mode 160000 index 0000000..b75edfa --- /dev/null +++ b/lib/spdlog @@ -0,0 +1 @@ +Subproject commit b75edfafca581e33be29ab51b9546b2e955c2853 diff --git a/tinyphone-osx/Tinyphone.xcodeproj/project.pbxproj b/tinyphone-osx/Tinyphone.xcodeproj/project.pbxproj index 1c9ff3d..86b9256 100644 --- a/tinyphone-osx/Tinyphone.xcodeproj/project.pbxproj +++ b/tinyphone-osx/Tinyphone.xcodeproj/project.pbxproj @@ -477,7 +477,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", + "_DEBUG=1", "$(inherited)", ); GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -496,10 +496,11 @@ ../lib/pjproject/pjmedia/include, ../lib/pjproject/pjsip/include, ../lib/curl/include, - "/Volumes/Workspace/code/voice/tinyphone/lib/pjproject/pjlib-util/include", + "../lib/pjproject/pjlib-util/include", ../lib, "../lib/statsd-cpp/include", ../lib/portaudio/include, + ../lib/spdlog/include, ); LIBRARY_SEARCH_PATHS = /usr/local/lib; MACOSX_DEPLOYMENT_TARGET = 10.15; @@ -573,10 +574,11 @@ ../lib/pjproject/pjmedia/include, ../lib/pjproject/pjsip/include, ../lib/curl/include, - "/Volumes/Workspace/code/voice/tinyphone/lib/pjproject/pjlib-util/include", + "../lib/pjproject/pjlib-util/include", ../lib, "../lib/statsd-cpp/include", ../lib/portaudio/include, + ../lib/spdlog/include, ); LIBRARY_SEARCH_PATHS = /usr/local/lib; MACOSX_DEPLOYMENT_TARGET = 10.15; diff --git a/tinyphone/server.h b/tinyphone/server.h index 4bb05f7..29b1a0b 100644 --- a/tinyphone/server.h +++ b/tinyphone/server.h @@ -12,30 +12,37 @@ #include "metrics.h" #include "log.h" #include "phone.h" +#include "spdlog/spdlog.h" +#include "spdlog/sinks/basic_file_sink.h" + class TinyPhoneHTTPLogHandler : public crow::ILogHandler { private: - std::fstream log_writer; - boost::iostreams::stream_buffer sb; + std::shared_ptr logger; + // std::fstream log_writer; + // boost::iostreams::stream_buffer sb; public: TinyPhoneHTTPLogHandler(std::string log_file) { - log_writer.open(log_file, std::fstream::out | std::fstream::app); - sb.open(LoggerSink(log_writer)); - std::cerr.clear(); - std::cerr.rdbuf(&sb); + try { + logger = spdlog::basic_logger_mt("http_logger", log_file); + } catch (const spdlog::spdlog_ex &ex) { + std::cout << "Log init failed: " << ex.what() << std::endl; + } + //std::cerr.clear(); + //std::cerr.rdbuf(&sb); }; ~TinyPhoneHTTPLogHandler() { - log_writer.flush(); - log_writer.close(); + logger->flush(); + //logger->close(); } void log(const std::string message, crow::LogLevel /*level*/) { - log_writer << message << std::endl ; + logger->info(message); #ifdef _DEBUG std::cout << message << std::endl ; #endif - log_writer.flush(); + logger->flush(); } }; diff --git a/tinyphone/tinyphone.vcxproj b/tinyphone/tinyphone.vcxproj index c671a80..485f969 100644 --- a/tinyphone/tinyphone.vcxproj +++ b/tinyphone/tinyphone.vcxproj @@ -90,7 +90,7 @@ Disabled WIN32;_DEBUG;_CONSOLE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true - E:\lib\statsd-cpp\include;E:\lib\portaudio\include;..\lib;..\lib\curl\include;..\lib\json\single_include;C:\local\boost_1_74_0;..\lib\crow\include;..\lib\pjproject\pjnath\include;..\lib\pjproject\pjmedia\include;..\lib\pjproject\pjlib-util\include;..\lib\pjproject\pjlib\include;..\lib\pjproject\pjsip\include;%(AdditionalIncludeDirectories) + ..\lib\spdlog\include;E:\lib\statsd-cpp\include;E:\lib\portaudio\include;..\lib;..\lib\curl\include;..\lib\json\single_include;C:\local\boost_1_74_0;..\lib\crow\include;..\lib\pjproject\pjnath\include;..\lib\pjproject\pjmedia\include;..\lib\pjproject\pjlib-util\include;..\lib\pjproject\pjlib\include;..\lib\pjproject\pjsip\include;%(AdditionalIncludeDirectories) MultiThreadedDebug true @@ -133,7 +133,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true - E:\lib\statsd-cpp\include;E:\lib\portaudio\include;..\lib;..\lib\curl\include;..\lib\json\single_include;C:\local\boost_1_74_0;..\lib\crow\include;..\lib\pjproject\pjnath\include;..\lib\pjproject\pjmedia\include;..\lib\pjproject\pjlib-util\include;..\lib\pjproject\pjlib\include;..\lib\pjproject\pjsip\include;%(AdditionalIncludeDirectories) + ..\lib\spdlog\include;E:\lib\statsd-cpp\include;E:\lib\portaudio\include;..\lib;..\lib\curl\include;..\lib\json\single_include;C:\local\boost_1_74_0;..\lib\crow\include;..\lib\pjproject\pjnath\include;..\lib\pjproject\pjmedia\include;..\lib\pjproject\pjlib-util\include;..\lib\pjproject\pjlib\include;..\lib\pjproject\pjsip\include;%(AdditionalIncludeDirectories) true