Conversation
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
|
Tests and probably implementation of the multithreaded text logger with flush handler are not yet in place, hence I put this as a draft. The rest can already be reviewed. Any input is already appreciated, specially regarding the flush handler (which we don't have to expose yet, but I thought I'd be nice to add). |
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
|
I have several What's missing:
|
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
|
Benchmark works fine locally. @mgovers could you run it in windows and WLS from this branch locally to confirm please. Only missing thing is to add the "end-to-end" test. Btw, since the text logger adds a timestamp already, given the fact the we use an internal timer already (in current implementation), we would have a "double" timestamp. I went with this decision because I'm unsure if everything will go via the timer in the future, and the timer itself doesn't give us a timestamp like we would like it for the text logger. This is definitely something to look at but I consider it out of scope for when we want to polish the loggers. What do you think? |
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
| */ | ||
| BatchParameter calculate(Options const& options, MutableDataset const& result_data, | ||
| ConstDataset const& update_data) { | ||
| info_.clear(); |
There was a problem hiding this comment.
please double-check whether the calculation info still works correctly
There was a problem hiding this comment.
This works, but now the user is responsible for cleaning between different calculations (if desired) if the same logger is used. Hence the benchmark has been adjusted to this.
Done. Both Windows and WSL pass |
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
| template <LazyLoggingFn Fn> void log(LogEvent tag, Fn&& fn) { log(tag, std::invoke(std::forward<Fn>(fn))); } | ||
| template <LazyLoggingFn Fn> void log(Fn&& fn) { log(LogEvent::unknown, std::invoke(std::forward<Fn>(fn))); } |
There was a problem hiding this comment.
can you explain why you went for std::invoke? not against it, just interested
There was a problem hiding this comment.
No particular reason. Doing fn() should suffice here as I require it to be std::invocable, but I guess I went with the more "generic" option.
| !std::derived_from<std::remove_cvref_t<std::tuple_element_t<0, std::tuple<Args...>>>, | ||
| MultiThreadedLoggerImpl> && |
There was a problem hiding this comment.
so what happens when it's of the form
MultiThreadedLoggerImpl other;
MultiThreadedLoggerImpl current{other, some_other_arg};?
does it need to be explicitly deleted?
There was a problem hiding this comment.
It doesn't need to be explicitly deleted because in MultiThreadedLoggerImpl current{other, some_other_arg} the first argument is also of type MultiThreadedLoggerImpl, which the concept forbids. This way, a MultiThreadedTextLogger recognizes a constructor with a FlushHandler present, but it prevents this constructor from triggering instead of the copy constructor during overload resolution. For instance, it allows:
MultiThreadedLoggerImpl logger{flush_handler};
MultiThreadedLoggerImpl copy{logger};| using namespace std::chrono; | ||
| const auto now = system_clock::now(); | ||
| const auto sec = floor<seconds>(now); | ||
| const auto ms = duration_cast<milliseconds>(now - sec).count(); | ||
|
|
||
| // Z stands for UTC time zone | ||
| // format example: 2026-04-25 14:00:00.000Z | ||
| return std::format("{:%F %T}.{:03}Z", sec, ms); |
There was a problem hiding this comment.
isn't there a direct formatted std::chrono? or is that C++26?
There was a problem hiding this comment.
This is the current way as far as I know (cfr. https://en.cppreference.com/w/cpp/chrono/system_clock/formatter.html).
| if (&destination == this) { | ||
| return destination; // nothing to do | ||
| } | ||
| destination.data_ << data_.str(); |
There was a problem hiding this comment.
prevents unneeded copy
| destination.data_ << data_.str(); | |
| destination.data_ << data_.view(); |
There was a problem hiding this comment.
The copy is needed here. destination.data_ << data_.view(); would provide a string_view which can dangle.
For example, consider the user provided logger and a batch calculation with multithreading enabled. If we use a view here, once the child threads are done with the calculation, they merge_into the main logger and then they are deleted. That would be a problem.
Signed-off-by: Santiago Figueroa Manrique <figueroa1395@gmail.com>
| template <LazyLoggingFn Fn> void log(LogEvent tag, Fn&& fn) { log(tag, std::invoke(std::forward<Fn>(fn))); } | ||
| template <LazyLoggingFn Fn> void log(Fn&& fn) { log(LogEvent::unknown, std::invoke(std::forward<Fn>(fn))); } |
There was a problem hiding this comment.
@mgovers @nitbharambe Should we already make this something like
| template <LazyLoggingFn Fn> void log(LogEvent tag, Fn&& fn) { log(tag, std::invoke(std::forward<Fn>(fn))); } | |
| template <LazyLoggingFn Fn> void log(Fn&& fn) { log(LogEvent::unknown, std::invoke(std::forward<Fn>(fn))); } | |
| template <LazyLoggingFn Fn> void log(LogEvent tag, Fn&& fn, bool invoke = false ) { | |
| if (!invoke) { return; } | |
| log(tag, std::invoke(std::forward<Fn>(fn))); } | |
| template <LazyLoggingFn Fn> void log(Fn&& fn, , bool invoke = false ) { | |
| if (!invoke) { return; } | |
| log(LogEvent::unknown, std::invoke(std::forward<Fn>(fn))); } |
to make it truly lazy already?
|



This PR implements a text logger in the core with multithreaded capability. Unit tests are added.