feat(logging): add CerrLogger std::cerr backend (3/6)#724
Conversation
7f46cc5 to
0dbc548
Compare
d3237ab to
77acb0e
Compare
| std::string FormatLine(const LogMessage& message) { | ||
| auto now = | ||
| std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now()); | ||
| return std::format("{:%Y-%m-%dT%H:%M:%S}Z {} [{}] {}:{}] {}\n", now, |
There was a problem hiding this comment.
The format has file:line], with a closing ] but no opening [. This looks like a typo. Please use [file:line] or file:line, and add a test that checks this part of the layout.
There was a problem hiding this comment.
Seems not resolved. See my comment below.
There was a problem hiding this comment.
Done. uploaded a wrong version.
77acb0e to
5a1845f
Compare
9989da5 to
865a07b
Compare
865a07b to
77f50dd
Compare
| std::string FormatLine(const LogMessage& message) { | ||
| auto now = | ||
| std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now()); | ||
| return std::format("{:%Y-%m-%dT%H:%M:%S}Z {} [{}] {}:{}] {}\n", now, |
There was a problem hiding this comment.
The PR description says the layout is [file:line], but this still emits file:line]. Please update the format string, the header doc, and the regex test to use the same layout.
| util/struct_like_set.cc | ||
| util/task_group.cc | ||
| util/temporal_util.cc | ||
| util/thread_util_internal.cc |
There was a problem hiding this comment.
We can just use thread_util.cc as its name without internal suffix.
| std::string FormatLine(const LogMessage& message) { | ||
| auto now = | ||
| std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now()); | ||
| return std::format("{:%Y-%m-%dT%H:%M:%S}Z {} [{}] {}:{}] {}\n", now, |
There was a problem hiding this comment.
Seems not resolved. See my comment below.
|
|
||
| /// \brief Trailing path component of a source file path. | ||
| std::string_view Basename(std::string_view path) noexcept { | ||
| auto pos = path.find_last_of("/\\"); |
There was a problem hiding this comment.
Is this platform compatible? Should we use std::filesystem?
96caa72 to
65d2d43
Compare
Third block: the first concrete sink, and the process default until the spdlog backend lands. - CerrLogger writes to std::cerr with a fixed line layout `YYYY-MM-DDThh:mm:ss.mmmZ LEVEL [tid] file:line] message`. Timestamps use UTC std::chrono floored to milliseconds (no gmtime/localtime -- thread-unsafe); the thread id is the OS-native id, cached per thread. - Level is a std::atomic<LogLevel>; a mutex guards the whole formatted-line write so concurrent lines never interleave. Log()/Flush() wrap stream ops in try/catch so the noexcept contract holds even if the stream throws. - MakeDefaultLogger() now returns CerrLogger. Wired into both builds and installed; cerr_logger_test covers layout, level filtering, and concurrent-write safety. Co-authored-by: Isaac
65d2d43 to
0b106c2
Compare
Part 3 of the logging stack — now based on
main(#723 merged). Adds the first concrete sink: a dependency-freestd::cerrlogger, also the default backend when spdlog is off.What's here
CerrLoggerwrites one line per record:YYYY-MM-DDThh:mm:ss.mmmZ LEVEL [tid] [file:line] message.util/thread_util.h), lock-free level check, and a whole-line mutex so concurrent records never interleave.Log/Flushnever throw. Inherits the baseInitialize("level");patternis ignored (fixed layout; only the spdlog backend honorspattern).Tests (
cerr_logger_test): level filtering, the fixed line layout incl. the.mmmfield and[file:line], inheritedInitialize,Flush, never-throw when the sink itself throws, and concurrent-write non-interleaving. Built/run under clang-libc++; ASan + TSan clean.This pull request and its description were written by Isaac.