diff --git a/.clang-format b/.clang-format index 078c4d6..90542e2 100644 --- a/.clang-format +++ b/.clang-format @@ -4,13 +4,12 @@ BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: None -AlignOperands: Align +AlignOperands: DontAlign AllowAllArgumentsOnNextLine: false AllowAllConstructorInitializersOnNextLine: false AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: Always AllowShortCaseLabelsOnASingleLine: false -AllowShortEnumsOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortIfStatementsOnASingleLine: true AllowShortLambdasOnASingleLine: All @@ -53,9 +52,6 @@ ObjCSpaceBeforeProtocolList: false PointerAlignment: Right ReflowComments: false SortIncludes: Never -AlignArrayOfStructures: Right -# AlignConsecutiveStyle: AcrossEmptyLines -AlignConsecutiveMacros: AcrossEmptyLines SpaceAfterCStyleCast: true SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: false diff --git a/.gitignore b/.gitignore index b54d73a..d558663 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,9 @@ _deps .idea/ cmake-build-* build/ +out/ .cache/ compile_commands.json +cmake-kits.json +CMakeKits.json \ No newline at end of file diff --git a/src/ulib/log/log.h b/src/ulib/log/log.h index 2f7fe0e..8aad8a1 100644 --- a/src/ulib/log/log.h +++ b/src/ulib/log/log.h @@ -6,17 +6,17 @@ #define ULIB_SRC_LOG_LOG_H_ #include "logger.h" +#include "level.h" #include namespace tqcq { -#define _ULOG(level, tag, fmt_str, ...) \ - tqcq::Logger::GetInstance().Log(level, __FILE__, __FUNCTION__, __LINE__, tag, \ +#define _ULOG(level, tag, fmt_str, ...) \ + tqcq::Logger::GetInstance().Log(level, __FILE__, __FUNCTION__, __LINE__, tag, \ fmt::format(fmt_str, ##__VA_ARGS__).c_str()) #define ULOG_SET_STRIPPED_PREFIX_LEN(len) ::tqcq::Logger::GetInstance().SetStrippedPrefixLen(len) - #if ULOG_LEVEL <= ULOG_LEVEL_TRACE #define ULOG_TRACE(...) _ULOG(ULOG_LEVEL_TRACE, __VA_ARGS__) #else @@ -53,8 +53,6 @@ namespace tqcq { #define ULOG_FATAL(...) ((void) 0) #endif -// class Log {}; - }// namespace tqcq #endif//ULIB_SRC_LOG_LOG_H_ diff --git a/src/ulib/log/logger.cpp b/src/ulib/log/logger.cpp index 98b6e0a..55b291e 100644 --- a/src/ulib/log/logger.cpp +++ b/src/ulib/log/logger.cpp @@ -5,8 +5,6 @@ #include "logger.h" #include #include -#include -#include #include #include #include @@ -21,13 +19,14 @@ Logger::GetInstance() return instance; } -Logger::Logger() { - const char* env_level = getenv("ULIB_LOG_LEVEL"); +Logger::Logger() +{ + const char *env_level = getenv("ULIB_LOG_LEVEL"); if (!env_level) { SetLogLevel(Level::kALL); } else { - char buffer[1024] = "invalid ULIB_LOG_LEVEL="; - for (const char* ptr = env_level; ptr && *ptr; ++ptr) { + char buffer[1024] = "invalid ULIB_LOG_LEVEL="; + for (const char *ptr = env_level; ptr && *ptr; ++ptr) { if (!isdigit(*ptr)) { strncat(buffer + strlen(buffer), env_level, 1000); Log(Level::kError, "logger.cpp", __FUNCTION__, __LINE__, "ulib.log", buffer); @@ -44,11 +43,9 @@ Logger::Logger() { Logger::~Logger() {} void -Logger::Log(int32_t level, const char *file, const char *func, int32_t line, const char* tag, const char *msg) +Logger::Log(int32_t level, const char *file, const char *func, int32_t line, const char *tag, const char *msg) { - if (level < level_) { - return; - } + if (level < level_) { return; } const char *level_name = Level::ToString(level); /** * @brief time file:line@func tag level_name msg @@ -57,20 +54,20 @@ Logger::Log(int32_t level, const char *file, const char *func, int32_t line, con std::string log_time; { std::time_t now = time(NULL); - std::tm* timeinfo = std::localtime(&now); + std::tm *timeinfo = std::localtime(&now); struct timeval timeval_now; gettimeofday(&timeval_now, NULL); - log_time = fmt::format("{:02}-{:02} {:02}:{:02}:{:02}.{:06}", timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, timeval_now.tv_usec); + log_time = fmt::format("{:02}-{:02} {:02}:{:02}:{:02}.{:06}", timeinfo->tm_mon + 1, timeinfo->tm_mday, + timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, timeval_now.tv_usec); } // auto add CR bool need_append_line_break = !msg || *msg == '\0' || msg[strlen(msg) - 1] != '\n'; - if (need_append_line_break) { - pattern.append(1, '\n'); - } + if (need_append_line_break) { pattern.append(1, '\n'); } fmt::print(pattern, log_time, file + stripped_prefix_len_, line, func, tag, level_name, msg); + std::fflush(stdout); } void diff --git a/src/ulib/log/logger.h b/src/ulib/log/logger.h index 01af1a4..1f8191a 100644 --- a/src/ulib/log/logger.h +++ b/src/ulib/log/logger.h @@ -6,8 +6,7 @@ #define ULIB_SRC_LOG_LOGGER_H_ #include "level.h" -#include "ulib/base/types.h" -#include +#include namespace tqcq { @@ -17,7 +16,7 @@ public: ~Logger(); static Logger &GetInstance(); void SetLogLevel(Level::LevelEnum min_level); - void Log(int32_t level, const char *file, const char *func, int32_t line, const char* tag,const char *msg); + void Log(int32_t level, const char *file, const char *func, int32_t line, const char *tag, const char *msg); void SetStrippedPrefixLen(size_t len); private: