feature add fflush after fmt::print
Some checks failed
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Failing after 1m0s
rpcrypto-build / build (Debug, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Failing after 55s
linux-mips64-gcc / linux-gcc-mips64el (push) Failing after 55s
linux-x64-gcc / linux-gcc (push) Failing after 48s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Failing after 1m13s
rpcrypto-build / build (Release, mipsel-openwrt-linux.toolchain.cmake) (push) Failing after 1m18s
rpcrypto-build / build (Release, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Failing after 1m14s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Failing after 1m29s
rpcrypto-build / build (Debug, mipsel-openwrt-linux.toolchain.cmake) (push) Failing after 1m21s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Failing after 1m7s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Failing after 1m17s
Some checks failed
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Failing after 1m0s
rpcrypto-build / build (Debug, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Failing after 55s
linux-mips64-gcc / linux-gcc-mips64el (push) Failing after 55s
linux-x64-gcc / linux-gcc (push) Failing after 48s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Failing after 1m13s
rpcrypto-build / build (Release, mipsel-openwrt-linux.toolchain.cmake) (push) Failing after 1m18s
rpcrypto-build / build (Release, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Failing after 1m14s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Failing after 1m29s
rpcrypto-build / build (Debug, mipsel-openwrt-linux.toolchain.cmake) (push) Failing after 1m21s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Failing after 1m7s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Failing after 1m17s
This commit is contained in:
parent
87527916bb
commit
b0135ddb71
@ -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
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -49,6 +49,9 @@ _deps
|
||||
.idea/
|
||||
cmake-build-*
|
||||
build/
|
||||
out/
|
||||
|
||||
.cache/
|
||||
compile_commands.json
|
||||
cmake-kits.json
|
||||
CMakeKits.json
|
@ -6,17 +6,17 @@
|
||||
#define ULIB_SRC_LOG_LOG_H_
|
||||
|
||||
#include "logger.h"
|
||||
#include "level.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
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_
|
||||
|
@ -5,8 +5,6 @@
|
||||
#include "logger.h"
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/time.h>
|
||||
#include <sstream>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
@ -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
|
||||
|
@ -6,8 +6,7 @@
|
||||
#define ULIB_SRC_LOG_LOGGER_H_
|
||||
|
||||
#include "level.h"
|
||||
#include "ulib/base/types.h"
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user