|
4 | 4 | #include <fmt/compile.h> |
5 | 5 | #include <fmt/format.h> |
6 | 6 |
|
7 | | -#include <userver/compiler/thread_local.hpp> |
8 | 7 | #include <userver/logging/impl/logger_base.hpp> |
| 8 | +#include <userver/logging/impl/timestamp.hpp> |
9 | 9 | #include <userver/ugrpc/impl/to_string.hpp> |
10 | 10 | #include <userver/utils/datetime.hpp> |
11 | 11 | #include <userver/utils/encoding/tskv.hpp> |
12 | | -#include <userver/utils/impl/source_location.hpp> |
13 | 12 | #include <userver/utils/text_light.hpp> |
14 | 13 |
|
15 | 14 | USERVER_NAMESPACE_BEGIN |
@@ -41,39 +40,6 @@ std::string ParseIp(std::string_view sv) { |
41 | 40 | return EscapeForAccessTskvLog(sv); |
42 | 41 | } |
43 | 42 |
|
44 | | -using SecondsTimePoint = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>; |
45 | | - |
46 | | -constexpr std::string_view kTimeTemplate = "0000-00-00T00:00:00"; |
47 | | - |
48 | | -struct CachedTime final { |
49 | | - SecondsTimePoint cached_time{}; |
50 | | - char cached_time_string[kTimeTemplate.size()]{}; |
51 | | -}; |
52 | | - |
53 | | -compiler::ThreadLocal local_time_cache = [] { return CachedTime{}; }; |
54 | | - |
55 | | -std::string_view GetCurrentTimeString(std::chrono::system_clock::time_point start_time) noexcept { |
56 | | - auto cache = local_time_cache.Use(); |
57 | | - const auto rounded_now = std::chrono::time_point_cast<std::chrono::seconds>(start_time); |
58 | | - if (rounded_now != cache->cached_time) { |
59 | | - fmt::format_to( |
60 | | - cache->cached_time_string, |
61 | | - FMT_COMPILE("{:%FT%T}"), |
62 | | - fmt::localtime(std::chrono::system_clock::to_time_t(start_time)) |
63 | | - ); |
64 | | - cache->cached_time = rounded_now; |
65 | | - } |
66 | | - |
67 | | -#ifdef __clang__ |
68 | | -#pragma clang diagnostic push |
69 | | -#pragma clang diagnostic ignored "-Wreturn-stack-address" |
70 | | -#endif |
71 | | - return std::string_view{cache->cached_time_string, kTimeTemplate.size()}; |
72 | | -#ifdef __clang__ |
73 | | -#pragma clang diagnostic pop |
74 | | -#endif |
75 | | -} |
76 | | - |
77 | 43 | } // namespace |
78 | 44 |
|
79 | 45 | logging::impl::LogExtraTskvFormatter FormatLogMessage( |
@@ -113,7 +79,7 @@ logging::impl::LogExtraTskvFormatter FormatLogMessage( |
113 | 79 | "\tupstream_response_time={}.{:0>3}" |
114 | 80 | "\tgrpc_status={}" |
115 | 81 | "\tgrpc_status_code={}", |
116 | | - GetCurrentTimeString(start_time), |
| 82 | + logging::impl::GetCurrentLocalTimeString(start_time).ToStringView(), |
117 | 83 | kTimezone, |
118 | 84 | EscapeForAccessTskvLog(user_agent), |
119 | 85 | ip, |
|
0 commit comments