From f5d3fcdf63737d19395a1ff8781998d4cdff03f2 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:40:29 +0800 Subject: [PATCH] fix(date): file log add date, month start with 1 --- tile/base/internal/logging.cc | 2 +- tile/base/logging/basic_file_sink.cc | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tile/base/internal/logging.cc b/tile/base/internal/logging.cc index f14e07e..e04c4b7 100644 --- a/tile/base/internal/logging.cc +++ b/tile/base/internal/logging.cc @@ -389,7 +389,7 @@ LogSink::ToString(LogSeverity severity, { std::stringstream ss; char date_time[64]; - sprintf(date_time, "%4d-%02d-%02dT%02d:%02d:%02d.%06d", logmsgtime.year() + 1900, logmsgtime.month(), + sprintf(date_time, "%4d-%02d-%02dT%02d:%02d:%02d.%06d", logmsgtime.year() + 1900, logmsgtime.month() + 1, logmsgtime.day(), logmsgtime.hour(), logmsgtime.min(), logmsgtime.sec(), logmsgtime.usec()); ss << date_time; diff --git a/tile/base/logging/basic_file_sink.cc b/tile/base/logging/basic_file_sink.cc index 38d5210..6648d0b 100644 --- a/tile/base/logging/basic_file_sink.cc +++ b/tile/base/logging/basic_file_sink.cc @@ -23,6 +23,8 @@ BasicFileSink::Send(LogSeverity severity, size_t message_len) { TILE_CHECK(!filepath_.empty(), "filepath is empty"); + auto msg = ToString(severity, full_filename, base_filename, line, logmsgtime, message, message_len); + while (!msg.empty() && msg.back() != '\n') { msg.push_back('\n'); } ofs_ << std::string(message, message_len) << std::endl; }