Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prefix http-log with timestamp #68

Merged
merged 8 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/spdlog
Submodule spdlog added at b75edf
1 change: 1 addition & 0 deletions tinyphone-linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/
target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/portaudio/include)
target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone)
target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/spdlog/include)
link_directories(tinyphone ${Boost_LIBRARY_DIRS})
target_link_libraries(tinyphone ${Boost_LIBRARIES})
target_link_libraries(tinyphone ${PJSIP_LIBRARIES})
Expand Down
8 changes: 5 additions & 3 deletions tinyphone-osx/Tinyphone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 12 additions & 6 deletions tinyphone/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,36 @@
#include "metrics.h"
#include "log.h"
#include "phone.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/ostream_sink.h"


class TinyPhoneHTTPLogHandler : public crow::ILogHandler {
private:
std::fstream log_writer;
boost::iostreams::stream_buffer<LoggerSink> sb;
std::shared_ptr<spdlog::logger> logger;
std::fstream log_writer;
boost::iostreams::stream_buffer<LoggerSink> sb;
public:
TinyPhoneHTTPLogHandler(std::string log_file) {
log_writer.open(log_file, std::fstream::out | std::fstream::app);
sb.open(LoggerSink(log_writer));
auto ostream_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(log_writer);
logger = std::make_shared<spdlog::logger>("http_logger", ostream_sink);
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();
}
};

Expand Down
4 changes: 2 additions & 2 deletions tinyphone/tinyphone.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>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)</AdditionalIncludeDirectories>
<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)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
Expand Down Expand Up @@ -133,7 +133,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>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)</AdditionalIncludeDirectories>
<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)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
Expand Down