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
|
AccessModifierOffset: -4
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveAssignments: None
|
AlignConsecutiveAssignments: None
|
||||||
AlignOperands: Align
|
AlignOperands: DontAlign
|
||||||
AllowAllArgumentsOnNextLine: false
|
AllowAllArgumentsOnNextLine: false
|
||||||
AllowAllConstructorInitializersOnNextLine: false
|
AllowAllConstructorInitializersOnNextLine: false
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
AllowShortBlocksOnASingleLine: Always
|
AllowShortBlocksOnASingleLine: Always
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
AllowShortEnumsOnASingleLine: true
|
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: true
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
AllowShortLambdasOnASingleLine: All
|
AllowShortLambdasOnASingleLine: All
|
||||||
@ -53,9 +52,6 @@ ObjCSpaceBeforeProtocolList: false
|
|||||||
PointerAlignment: Right
|
PointerAlignment: Right
|
||||||
ReflowComments: false
|
ReflowComments: false
|
||||||
SortIncludes: Never
|
SortIncludes: Never
|
||||||
AlignArrayOfStructures: Right
|
|
||||||
# AlignConsecutiveStyle: AcrossEmptyLines
|
|
||||||
AlignConsecutiveMacros: AcrossEmptyLines
|
|
||||||
SpaceAfterCStyleCast: true
|
SpaceAfterCStyleCast: true
|
||||||
SpaceAfterLogicalNot: false
|
SpaceAfterLogicalNot: false
|
||||||
SpaceAfterTemplateKeyword: false
|
SpaceAfterTemplateKeyword: false
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -49,6 +49,9 @@ _deps
|
|||||||
.idea/
|
.idea/
|
||||||
cmake-build-*
|
cmake-build-*
|
||||||
build/
|
build/
|
||||||
|
out/
|
||||||
|
|
||||||
.cache/
|
.cache/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
cmake-kits.json
|
||||||
|
CMakeKits.json
|
@ -6,17 +6,17 @@
|
|||||||
#define ULIB_SRC_LOG_LOG_H_
|
#define ULIB_SRC_LOG_LOG_H_
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "level.h"
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
namespace tqcq {
|
namespace tqcq {
|
||||||
|
|
||||||
#define _ULOG(level, tag, fmt_str, ...) \
|
#define _ULOG(level, tag, fmt_str, ...) \
|
||||||
tqcq::Logger::GetInstance().Log(level, __FILE__, __FUNCTION__, __LINE__, tag, \
|
tqcq::Logger::GetInstance().Log(level, __FILE__, __FUNCTION__, __LINE__, tag, \
|
||||||
fmt::format(fmt_str, ##__VA_ARGS__).c_str())
|
fmt::format(fmt_str, ##__VA_ARGS__).c_str())
|
||||||
|
|
||||||
#define ULOG_SET_STRIPPED_PREFIX_LEN(len) ::tqcq::Logger::GetInstance().SetStrippedPrefixLen(len)
|
#define ULOG_SET_STRIPPED_PREFIX_LEN(len) ::tqcq::Logger::GetInstance().SetStrippedPrefixLen(len)
|
||||||
|
|
||||||
|
|
||||||
#if ULOG_LEVEL <= ULOG_LEVEL_TRACE
|
#if ULOG_LEVEL <= ULOG_LEVEL_TRACE
|
||||||
#define ULOG_TRACE(...) _ULOG(ULOG_LEVEL_TRACE, __VA_ARGS__)
|
#define ULOG_TRACE(...) _ULOG(ULOG_LEVEL_TRACE, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
@ -53,8 +53,6 @@ namespace tqcq {
|
|||||||
#define ULOG_FATAL(...) ((void) 0)
|
#define ULOG_FATAL(...) ((void) 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// class Log {};
|
|
||||||
|
|
||||||
}// namespace tqcq
|
}// namespace tqcq
|
||||||
|
|
||||||
#endif//ULIB_SRC_LOG_LOG_H_
|
#endif//ULIB_SRC_LOG_LOG_H_
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <fmt/time.h>
|
#include <fmt/time.h>
|
||||||
#include <sstream>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@ -21,13 +19,14 @@ Logger::GetInstance()
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Logger() {
|
Logger::Logger()
|
||||||
const char* env_level = getenv("ULIB_LOG_LEVEL");
|
{
|
||||||
|
const char *env_level = getenv("ULIB_LOG_LEVEL");
|
||||||
if (!env_level) {
|
if (!env_level) {
|
||||||
SetLogLevel(Level::kALL);
|
SetLogLevel(Level::kALL);
|
||||||
} else {
|
} else {
|
||||||
char buffer[1024] = "invalid ULIB_LOG_LEVEL=";
|
char buffer[1024] = "invalid ULIB_LOG_LEVEL=";
|
||||||
for (const char* ptr = env_level; ptr && *ptr; ++ptr) {
|
for (const char *ptr = env_level; ptr && *ptr; ++ptr) {
|
||||||
if (!isdigit(*ptr)) {
|
if (!isdigit(*ptr)) {
|
||||||
strncat(buffer + strlen(buffer), env_level, 1000);
|
strncat(buffer + strlen(buffer), env_level, 1000);
|
||||||
Log(Level::kError, "logger.cpp", __FUNCTION__, __LINE__, "ulib.log", buffer);
|
Log(Level::kError, "logger.cpp", __FUNCTION__, __LINE__, "ulib.log", buffer);
|
||||||
@ -44,11 +43,9 @@ Logger::Logger() {
|
|||||||
Logger::~Logger() {}
|
Logger::~Logger() {}
|
||||||
|
|
||||||
void
|
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_) {
|
if (level < level_) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
const char *level_name = Level::ToString(level);
|
const char *level_name = Level::ToString(level);
|
||||||
/**
|
/**
|
||||||
* @brief time file:line@func tag level_name msg
|
* @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::string log_time;
|
||||||
{
|
{
|
||||||
std::time_t now = time(NULL);
|
std::time_t now = time(NULL);
|
||||||
std::tm* timeinfo = std::localtime(&now);
|
std::tm *timeinfo = std::localtime(&now);
|
||||||
|
|
||||||
struct timeval timeval_now;
|
struct timeval timeval_now;
|
||||||
gettimeofday(&timeval_now, NULL);
|
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
|
// auto add CR
|
||||||
bool need_append_line_break = !msg || *msg == '\0' || msg[strlen(msg) - 1] != '\n';
|
bool need_append_line_break = !msg || *msg == '\0' || msg[strlen(msg) - 1] != '\n';
|
||||||
if (need_append_line_break) {
|
if (need_append_line_break) { pattern.append(1, '\n'); }
|
||||||
pattern.append(1, '\n');
|
|
||||||
}
|
|
||||||
fmt::print(pattern, log_time, file + stripped_prefix_len_, line, func, tag, level_name, msg);
|
fmt::print(pattern, log_time, file + stripped_prefix_len_, line, func, tag, level_name, msg);
|
||||||
|
std::fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
#define ULIB_SRC_LOG_LOGGER_H_
|
#define ULIB_SRC_LOG_LOGGER_H_
|
||||||
|
|
||||||
#include "level.h"
|
#include "level.h"
|
||||||
#include "ulib/base/types.h"
|
#include <string.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace tqcq {
|
namespace tqcq {
|
||||||
|
|
||||||
@ -17,7 +16,7 @@ public:
|
|||||||
~Logger();
|
~Logger();
|
||||||
static Logger &GetInstance();
|
static Logger &GetInstance();
|
||||||
void SetLogLevel(Level::LevelEnum min_level);
|
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);
|
void SetStrippedPrefixLen(size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user