diff --git a/Makefile b/Makefile index 8969c4a900b613e0384162d645273a0688743cad..9a81e8d39ca892eec1ab4f4116c1931c79181441 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,9 @@ ifeq ($(PLATFORM), Darwin) clang++ test/main.cc -o out/log_test -Iinclude -Isrc -lpthread -llog4cc -L./out -std=c++17 -fPIC && install_name_tool -add_rpath $$(pwd)/out out/log_test clang test/main.c -o out/clog_test -Iinclude -Isrc -lpthread -llog4cc -L./out -fPIC && install_name_tool -add_rpath $$(pwd)/out out/clog_test else - clang++ test/main.cc -o out/log_test -Iinclude -Isrc -lpthread -llog4cc -L./out -Wl,--start-group,-rpath=$$(pwd)/out -Wl,--end-group -std=c++17 -fPIC - clang test/main.c -o out/clog_test -Iinclude -Isrc -lpthread -llog4cc -L./out -Wl,--start-group,-rpath=$$(pwd)/out -Wl,--end-group -fPIC + clang++ test/main.cc -o out/main_test -Iinclude -Isrc -lpthread -llog4cc -L./out -Wl,--start-group,-rpath=$$(pwd)/out -Wl,--end-group -std=c++17 -fPIC + clang test/main.c -o out/cmain_test -Iinclude -Isrc -lpthread -llog4cc -L./out -Wl,--start-group,-rpath=$$(pwd)/out -Wl,--end-group -fPIC + clang++ test/logtest.cc -o out/log_test -Iinclude -Isrc -lpthread -llog4cc -L./out -Wl,--start-group,-rpath=$$(pwd)/out -Wl,--end-group -std=c++17 -fPIC endif .PHONY: log diff --git a/src/log4cc_inner.h b/src/log4cc_inner.h index e274212aff88bef3f154cd609efc414308b1ab6b..6800fcc62a7223bdf7c955a3ee99784e0d2441dd 100644 --- a/src/log4cc_inner.h +++ b/src/log4cc_inner.h @@ -57,6 +57,8 @@ static const char LOG4CC_ERROR[] = "[ERROR]"; log.append(1, ' ').append(std::to_string(str)); \ } else if constexpr (std::is_same::type, double>::value) { \ log.append(1, ' ').append(std::to_string(str)); \ + } else if constexpr (std::is_same::type, bool>::value) { \ + log.append(1, ' ').append(std::to_string(str)); \ } else if constexpr (std::is_same::type, std::string_view>::value) { \ log.append(1, ' ').append(str); \ } else if constexpr (std::is_same::type, std::string>::value) { \ diff --git a/test/logtest.cc b/test/logtest.cc new file mode 100644 index 0000000000000000000000000000000000000000..dc32f56aa028ef9463081f0234a945674829f61c --- /dev/null +++ b/test/logtest.cc @@ -0,0 +1,89 @@ +/* + * MIT License + * Copyright (c) 2023 DoubleByte + * write by zhangzhewei + */ + +#include +#include + +#include "log4cc.h" + +void NumberTest() { + int num = 1; + short numShort = 2; + long numLong =3; + float numFloat = 1.88; + double numDouble = 1.8888; + + LOGI("number test"); + LOGI(1, num, numShort); + LOGD(2, numLong); + LOGW(3, numFloat); + LOGE(4, numDouble, "\n"); +} + +void StringTest() { + std::string string = "string"; + std::string_view stringVeiw = "string_veiw"; + char a[] = "char string"; + + LOGI("string test"); + LOGI("one", string); + LOGD("two", stringVeiw); + LOGW("three", a); + LOGE("four\n"); +} + +void CharTest() { + char a = 'a'; + char16_t b = 'b'; + char32_t c = 'c'; + uint8_t d = 'd'; + + LOGI("char test"); + LOGI('1', a); + LOGD('2', b); + LOGW('3', c); + LOGE('4', d, "\n"); +} + +void MemoryTest() { + size_t size = 18; + uint8_t uint8 = 8; + int8_t int8 = -8; + uint16_t uint16 = 16; + int16_t int16 = -16; + uint32_t uint32 = 32; + int32_t int32 = -32; + uint64_t uint64 = 64; + int64_t int64 = -64; + + LOGI("memory test"); + LOGI(size, uint8, int8); + LOGD(uint16, int16); + LOGW(uint32, int32); + LOGE(uint64, int64, "\n"); +} + +void BoolTest() { + bool flag = true; + bool flag_1 = false; + + LOGI("bool test"); + LOGI("ture", flag); + LOGD("false", flag_1, "\n"); +} + +int main() { + Log4ccInit(); + + NumberTest(); + StringTest(); + CharTest(); + MemoryTest(); + BoolTest(); + + Log4ccFree(); + return 0; +} \ No newline at end of file