logger
1.0.0
用於原始程式碼追蹤和調試的實用程式庫。
可以像介面(僅標頭)或共用庫一樣使用。
std::cout
- 預設兩個使用範例(僅標頭或共用程式庫)都可以在測試/LoggerMainTest 中找到。
std::cout
作為日誌輸出,請在程式碼中定義下一個變數: std::mutex nlab::logger::gCoutMutex; // used for output synchronization
如果沒有,請透過下一個定義關閉 cout 日誌記錄: LOG_OUTPUT_COUT_DISABLED
,例如 CMake:
add_definitions(-DLOG_OUTPUT_COUT_DISABLED`)
LOGGER_BUILD_HEADER_LIB=ON
,例如: cmake -DCMAKE_BUILD_TYPE=Release -DLOGGER_BUILD_HEADER_LIB=ON ..
或在頂部 CMake 檔案中,例如:
set(LOGGER_BUILD_HEADER_LIB ON CACHE BOOL "Build the header only library")
add_subdirectory(logger)
輸出從測試/LoggerMainTest 捕獲的範例
對於調試建置:
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cd tests
make
./LoggerMainTest
06-26 17:23:21.897 [--->] LoggerMainTest.cpp:16 main() ThreadId: 140718535841600
06-26 17:23:21.897 [--->] LoggerMainTest.cpp:60 main_th() ThreadId: 140718515595008
06-26 17:23:21.897 [--->] LoggerMainTest.cpp:60 main_th() ThreadId: 140718507202304
06-26 17:23:21.897 [--->] LoggerMainTest.cpp:55 test2() ThreadId: 140718507202304
06-26 17:23:21.897 [--->] LoggerMainTest.cpp:55 test2() ThreadId: 140718515595008
06-26 17:23:21.897 [<---] LoggerMainTest.cpp:55 test2() ThreadId: 140718515595008
06-26 17:23:21.898 [<---] LoggerMainTest.cpp:55 test2() ThreadId: 140718507202304
06-26 17:23:21.998 [--->] LoggerMainTest.cpp:55 test2() ThreadId: 140718515595008
06-26 17:23:21.998 [<---] LoggerMainTest.cpp:55 test2() ThreadId: 140718515595008
06-26 17:23:21.998 [--->] LoggerMainTest.cpp:55 test2() ThreadId: 140718507202304
06-26 17:23:21.998 [<---] LoggerMainTest.cpp:55 test2() ThreadId: 140718507202304
06-26 17:23:22.098 [--->] LoggerMainTest.cpp:55 test2() ThreadId: 140718515595008
06-26 17:23:22.098 [<---] LoggerMainTest.cpp:55 test2() ThreadId: 140718515595008
06-26 17:23:22.098 [--->] LoggerMainTest.cpp:55 test2() ThreadId: 140718507202304
06-26 17:23:22.098 [<---] LoggerMainTest.cpp:55 test2() ThreadId: 140718507202304
06-26 17:23:22.198 [<---] LoggerMainTest.cpp:60 main_th() ThreadId: 140718515595008
06-26 17:23:22.198 [<---] LoggerMainTest.cpp:60 main_th() ThreadId: 140718507202304
06-26 17:23:22.198 [info] LoggerMainTest.cpp:24 main() Test Info 1
06-26 17:23:22.198 [warn] LoggerMainTest.cpp:25 main() Test Warning 2
06-26 17:23:22.198 [error] LoggerMainTest.cpp:26 main() Test Error 3
06-26 17:23:22.198 [debug] LoggerMainTest.cpp:27 main() Test Debug 4
06-26 17:23:22.198 [info] LoggerMainTest.cpp:30 main() Test 888 str c
06-26 17:23:22.199 [error] LoggerMainTest.cpp:33 main() ptr = nullptr
06-26 17:23:22.199 [--->] LoggerMainTest.cpp:50 test1() ThreadId: 140718535841600
06-26 17:23:22.199 [<---] LoggerMainTest.cpp:50 test1() ThreadId: 140718535841600
06-26 17:23:22.199 [--->] LoggerMainTest.cpp:50 test1() ThreadId: 140718535841600
06-26 17:23:22.199 [<---] LoggerMainTest.cpp:50 test1() ThreadId: 140718535841600
06-26 17:23:22.199 [--->] LoggerMainTest.cpp:50 test1() ThreadId: 140718535841600
06-26 17:23:22.199 [<---] LoggerMainTest.cpp:50 test1() ThreadId: 140718535841600
06-26 17:23:23.199 [<---] LoggerMainTest.cpp:16 main() ThreadId: 140718535841600
對於發布版本:
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cd tests
make
./LoggerMainTest
06-26 17:37:00.411 [info] LoggerMainTest.cpp:24 main() Test Info 1
06-26 17:37:00.411 [warn] LoggerMainTest.cpp:25 main() Test Warning 2
06-26 17:37:00.411 [error] LoggerMainTest.cpp:26 main() Test Error 3
06-26 17:37:00.411 [info] LoggerMainTest.cpp:30 main() Test 888 str c
06-26 17:37:00.411 [error] LoggerMainTest.cpp:33 main() ptr = nullptr