From 376a3fe493c5f98472e7e101bfdd938b45de9ccd Mon Sep 17 00:00:00 2001 From: zhangzhewei Date: Fri, 17 Feb 2023 14:04:20 +0800 Subject: [PATCH 1/2] fix log Signed-off-by: zhangzhewei --- .vscode/settings.json | 54 +++++++++++++++++++++++++++++++++++++++++++ Makefile | 5 ++-- src/log4cc_inner.h | 2 ++ test/logtest.cc | 33 ++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 test/logtest.cc diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bf3c216 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,54 @@ +{ + "files.associations": { + "algorithm": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index 8969c4a..9a81e8d 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 e274212..6800fcc 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 0000000..b6378db --- /dev/null +++ b/test/logtest.cc @@ -0,0 +1,33 @@ +/* + * MIT License + * Copyright (c) 2023 DoubleByte + * write by chengxuya + */ + +#include +#include + +#include "log4cc.h" + +constexpr char CHAR[] = "char"; +constexpr bool FLAG = false; +constexpr int32_t NUM_INT_32 = 88; +constexpr uint32_t NUM_UINT_32 = 88; +constexpr float NUM_FLOAT = 1.88; +constexpr double NUM_DOUBLE = 1.8888; +constexpr size_t NUM_SIZE = 18; +constexpr int8_t NUM_INT_8 = 12; +constexpr uint8_t NUM_UINT_8 = 0x1; + +int main() { + Log4ccInit(); + std::string string = "string"; + std::string_view stringVeiw = "string_veiw"; + LOGI(1, CHAR, string, stringVeiw, FLAG); + LOGD(2, NUM_INT_32, NUM_FLOAT); + LOGW(3, NUM_SIZE, NUM_INT_8); + LOGE(4, NUM_INT_32, NUM_UINT_32); + + Log4ccFree(); + return 0; +} \ No newline at end of file -- Gitee From fb82a4177dbf425c4510f31c3d7e15b94ad69a36 Mon Sep 17 00:00:00 2001 From: zhangzhewei Date: Thu, 23 Feb 2023 16:18:21 +0800 Subject: [PATCH 2/2] fix 2 23 Signed-off-by: zhangzhewei --- .vscode/settings.json | 54 -------------------------- test/logtest.cc | 90 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 71 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index bf3c216..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "files.associations": { - "algorithm": "cpp", - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/test/logtest.cc b/test/logtest.cc index b6378db..dc32f56 100644 --- a/test/logtest.cc +++ b/test/logtest.cc @@ -1,32 +1,88 @@ /* * MIT License * Copyright (c) 2023 DoubleByte - * write by chengxuya + * write by zhangzhewei */ +#include #include -#include #include "log4cc.h" -constexpr char CHAR[] = "char"; -constexpr bool FLAG = false; -constexpr int32_t NUM_INT_32 = 88; -constexpr uint32_t NUM_UINT_32 = 88; -constexpr float NUM_FLOAT = 1.88; -constexpr double NUM_DOUBLE = 1.8888; -constexpr size_t NUM_SIZE = 18; -constexpr int8_t NUM_INT_8 = 12; -constexpr uint8_t NUM_UINT_8 = 0x1; +void NumberTest() { + int num = 1; + short numShort = 2; + long numLong =3; + float numFloat = 1.88; + double numDouble = 1.8888; -int main() { - Log4ccInit(); + 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"; - LOGI(1, CHAR, string, stringVeiw, FLAG); - LOGD(2, NUM_INT_32, NUM_FLOAT); - LOGW(3, NUM_SIZE, NUM_INT_8); - LOGE(4, NUM_INT_32, NUM_UINT_32); + 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; -- Gitee