diff options
author | Alexey Salmin <alexey.salmin@gmail.com> | 2022-02-10 16:49:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:37 +0300 |
commit | 71af077a5dfe7e9f932a508422c2dac81a57ebc0 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/logger/global/rty_formater.cpp | |
parent | 3c5b1607b38f637d2f3313791ed25c2e080d2647 (diff) | |
download | ydb-71af077a5dfe7e9f932a508422c2dac81a57ebc0.tar.gz |
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/logger/global/rty_formater.cpp')
-rw-r--r-- | library/cpp/logger/global/rty_formater.cpp | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/library/cpp/logger/global/rty_formater.cpp b/library/cpp/logger/global/rty_formater.cpp index cce0070dcb..305f8470c5 100644 --- a/library/cpp/logger/global/rty_formater.cpp +++ b/library/cpp/logger/global/rty_formater.cpp @@ -1,53 +1,53 @@ #include "rty_formater.h" #include <util/datetime/base.h> -#include <util/datetime/systime.h> +#include <util/datetime/systime.h> #include <util/stream/str.h> #include <util/stream/printf.h> #include <util/system/mem_info.h> -#include <util/system/yassert.h> +#include <util/system/yassert.h> #include <inttypes.h> -#include <cstdio> +#include <cstdio> + +namespace { + constexpr size_t LocalTimeSBufferSize = sizeof("2017-07-24 12:20:34.313 +0300"); + + size_t PrintLocalTimeS(const TInstant instant, char* const begin, const char* const end) { + Y_VERIFY(static_cast<size_t>(end - begin) >= LocalTimeSBufferSize); -namespace { - constexpr size_t LocalTimeSBufferSize = sizeof("2017-07-24 12:20:34.313 +0300"); - - size_t PrintLocalTimeS(const TInstant instant, char* const begin, const char* const end) { - Y_VERIFY(static_cast<size_t>(end - begin) >= LocalTimeSBufferSize); - struct tm tm; - instant.LocalTime(&tm); - - // both stftime and sprintf exclude the terminating null byte from the return value + instant.LocalTime(&tm); + + // both stftime and sprintf exclude the terminating null byte from the return value char* pos = begin; - pos += strftime(pos, end - pos, "%Y-%m-%d %H:%M:%S.", &tm); - pos += sprintf(pos, "%03" PRIu32, instant.MilliSecondsOfSecond()); - pos += strftime(pos, end - pos, " %z", &tm); - Y_VERIFY(LocalTimeSBufferSize - 1 == pos - begin); // together with Y_VERIFY above this also implies pos<=end - return (pos - begin); + pos += strftime(pos, end - pos, "%Y-%m-%d %H:%M:%S.", &tm); + pos += sprintf(pos, "%03" PRIu32, instant.MilliSecondsOfSecond()); + pos += strftime(pos, end - pos, " %z", &tm); + Y_VERIFY(LocalTimeSBufferSize - 1 == pos - begin); // together with Y_VERIFY above this also implies pos<=end + return (pos - begin); } -} +} -namespace NLoggingImpl { +namespace NLoggingImpl { IOutputStream& operator<<(IOutputStream& out, TLocalTimeS localTimeS) { - char buffer[LocalTimeSBufferSize]; - size_t len = PrintLocalTimeS(localTimeS.GetInstant(), buffer, buffer + sizeof(buffer)); - out.Write(buffer, len); - return out; - } - - TLocalTimeS::operator TString() const { - TString res; - res.reserve(LocalTimeSBufferSize); - res.ReserveAndResize(PrintLocalTimeS(Instant, res.begin(), res.begin() + res.capacity())); - return res; - } - - TString TLocalTimeS::operator+(const TStringBuf right) const { - TString res(*this); - res += right; - return res; - } - + char buffer[LocalTimeSBufferSize]; + size_t len = PrintLocalTimeS(localTimeS.GetInstant(), buffer, buffer + sizeof(buffer)); + out.Write(buffer, len); + return out; + } + + TLocalTimeS::operator TString() const { + TString res; + res.reserve(LocalTimeSBufferSize); + res.ReserveAndResize(PrintLocalTimeS(Instant, res.begin(), res.begin() + res.capacity())); + return res; + } + + TString TLocalTimeS::operator+(const TStringBuf right) const { + TString res(*this); + res += right; + return res; + } + TStringBuf StripFileName(TStringBuf string) { return string.RNextTok(LOCSLASH_C); } |