diff --git a/compile_commands.json b/compile_commands.json index 01e885d..a97838a 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -114,6 +114,11 @@ "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -std=c++11 -o CMakeFiles/webcc.dir/soap_client.cc.o -c /home/adam/github/webcc/webcc/soap_client.cc", "file": "/home/adam/github/webcc/webcc/soap_client.cc" }, +{ + "directory": "/home/adam/github/webcc/build/webcc", + "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -std=c++11 -o CMakeFiles/webcc.dir/soap_globals.cc.o -c /home/adam/github/webcc/webcc/soap_globals.cc", + "file": "/home/adam/github/webcc/webcc/soap_globals.cc" +}, { "directory": "/home/adam/github/webcc/build/webcc", "command": "/usr/bin/c++ -DBOOST_ASIO_NO_DEPRECATED -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -std=c++11 -o CMakeFiles/webcc.dir/soap_message.cc.o -c /home/adam/github/webcc/webcc/soap_message.cc", @@ -159,6 +164,11 @@ "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_server.dir/__/common/book.cc.o -c /home/adam/github/webcc/example/common/book.cc", "file": "/home/adam/github/webcc/example/common/book.cc" }, +{ + "directory": "/home/adam/github/webcc/build/example/rest_book_server", + "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_server.dir/__/common/book_json.cc.o -c /home/adam/github/webcc/example/common/book_json.cc", + "file": "/home/adam/github/webcc/example/common/book_json.cc" +}, { "directory": "/home/adam/github/webcc/build/example/rest_book_server", "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_server.dir/services.cc.o -c /home/adam/github/webcc/example/rest_book_server/services.cc", @@ -169,11 +179,31 @@ "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_server.dir/main.cc.o -c /home/adam/github/webcc/example/rest_book_server/main.cc", "file": "/home/adam/github/webcc/example/rest_book_server/main.cc" }, +{ + "directory": "/home/adam/github/webcc/build/example/rest_book_client", + "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_client.dir/__/common/book.cc.o -c /home/adam/github/webcc/example/common/book.cc", + "file": "/home/adam/github/webcc/example/common/book.cc" +}, +{ + "directory": "/home/adam/github/webcc/build/example/rest_book_client", + "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_client.dir/__/common/book_json.cc.o -c /home/adam/github/webcc/example/common/book_json.cc", + "file": "/home/adam/github/webcc/example/common/book_json.cc" +}, { "directory": "/home/adam/github/webcc/build/example/rest_book_client", "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_client.dir/main.cc.o -c /home/adam/github/webcc/example/rest_book_client/main.cc", "file": "/home/adam/github/webcc/example/rest_book_client/main.cc" }, +{ + "directory": "/home/adam/github/webcc/build/example/rest_book_async_client", + "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_async_client.dir/__/common/book.cc.o -c /home/adam/github/webcc/example/common/book.cc", + "file": "/home/adam/github/webcc/example/common/book.cc" +}, +{ + "directory": "/home/adam/github/webcc/build/example/rest_book_async_client", + "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_async_client.dir/__/common/book_json.cc.o -c /home/adam/github/webcc/example/common/book_json.cc", + "file": "/home/adam/github/webcc/example/common/book_json.cc" +}, { "directory": "/home/adam/github/webcc/build/example/rest_book_async_client", "command": "/usr/bin/c++ -DWEBCC_ENABLE_LOG -DWEBCC_ENABLE_SOAP -DWEBCC_LOG_LEVEL=0 -I/usr/local/include -I/home/adam/github/webcc -I/home/adam/github/webcc/third_party/src -I/home/adam/github/webcc/third_party/src/jsoncpp -std=c++11 -o CMakeFiles/rest_book_async_client.dir/main.cc.o -c /home/adam/github/webcc/example/rest_book_async_client/main.cc", diff --git a/webcc/http_client.cc b/webcc/http_client.cc index 656b647..1d92e13 100644 --- a/webcc/http_client.cc +++ b/webcc/http_client.cc @@ -131,6 +131,8 @@ Error HttpClient::SendReqeust(const HttpRequest& request) { return kSocketWriteError; } + LOG_INFO("Request sent."); + return kNoError; } diff --git a/webcc/logger.cc b/webcc/logger.cc index 24abdc5..d351e80 100644 --- a/webcc/logger.cc +++ b/webcc/logger.cc @@ -11,6 +11,14 @@ #include #include +#if (defined(WIN32) || defined(_WIN64)) +// Do nothing. +#else +// For getting thread ID. +#include +#include +#endif + #include "boost/filesystem.hpp" namespace webcc { @@ -47,7 +55,7 @@ struct Logger { // Global logger. static Logger g_logger; -static std::thread::id g_main_thread_id; +static std::string g_main_thread_id; static const char* kLevelNames[] = { "VERB", "INFO", "WARN", "ERRO", "FATA" @@ -55,6 +63,28 @@ static const char* kLevelNames[] = { namespace bfs = boost::filesystem; +// std::this_thread::get_id() returns a very long ID (same as pthread_self()) +// on Linux, e.g., 140219133990656. syscall(SYS_gettid) is much prefered because +// it's shorter and the same as `ps -T -p ` output. +static std::string DoGetThreadID() { +#if (defined(WIN32) || defined(_WIN64)) + auto thread_id = std::this_thread::get_id(); + std::stringstream ss; + ss << thread_id; + return ss.str(); +#else + return std::to_string(syscall(SYS_gettid)); +#endif +} + +static std::string GetThreadID() { + std::string thread_id = DoGetThreadID(); + if (thread_id == g_main_thread_id) { + return "main"; + } + return thread_id; +} + static bfs::path InitLogPath(const std::string& dir) { if (dir.empty()) { return bfs::current_path() / WEBCC_LOG_FILE_NAME; @@ -81,7 +111,7 @@ void LogInit(const std::string& dir, int modes) { } // Suppose LogInit() is called from the main thread. - g_main_thread_id = std::this_thread::get_id(); + g_main_thread_id = DoGetThreadID(); } static std::string GetTimestamp() { @@ -109,18 +139,6 @@ static std::string GetTimestamp() { return timestamp; } -static std::string GetThreadID() { - std::thread::id thread_id = std::this_thread::get_id(); - - if (thread_id == g_main_thread_id) { - return "main"; - } - - std::stringstream ss; - ss << thread_id; - return ss.str(); -} - void LogWrite(int level, const char* file, int line, const char* format, ...) { assert(format != nullptr);