fix add line break when strlen(msg) == 0
Some checks failed
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Debug, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Debug, mipsel-openwrt-linux.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Release, mipsel-openwrt-linux-musl.toolchain.cmake) (push) Has been cancelled
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Has been cancelled
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Has been cancelled
rpcrypto-build / build (Release, mipsel-openwrt-linux.toolchain.cmake) (push) Has been cancelled
linux-mips64-gcc / linux-gcc-mips64el (push) Has been cancelled
linux-x64-gcc / linux-gcc (push) Has been cancelled

This commit is contained in:
tqcq 2023-12-11 13:28:07 +08:00
parent ef806f45c3
commit 214aa61f31

View File

@ -25,13 +25,14 @@ void
Logger::Log(int32_t level, const char *file, const char *func, int32_t line, const char *msg)
{
const char *level_name = Level::ToString(level);
fmt::print("[{}] {}:{}@{} msg: {}", level_name, file + stripped_prefix_len_, line, func, msg);
std::string pattern = "[{}] {}:{}@{} msg: {}";
// auto add CR
if (msg) {
size_t len = strlen(msg);
if (len > 0 && msg[len - 1] != '\n') { fmt::print("\n"); }
bool need_append_line_break = !msg || msg[strlen(msg) - 1] != '\n';
if (need_append_line_break) {
pattern.append(1, '\n');
}
fmt::print(pattern, level_name, file + stripped_prefix_len_, line, func, msg);
}
void