30#include <fmt/format.h>
58template <
typename Algorithm = std::monostate>
70 logger.config().iteration_output_period()),
72 logger.config().iteration_label_period()) {
110 auto append(std::string label, ParameterValue value)
112 auto parameter = std::make_shared<
114 std::move(label), std::move(value));
115 auto* raw_ptr = parameter.get();
116 append(std::move(parameter));
128 template <concepts::formattable_iteration_parameter_value Value>
129 auto append(std::string label,
const Value& value)
147 auto append(std::string label, Function&& function)
150 std::decay_t<Function>>>* {
153 std::decay_t<Function>>(std::forward<Function>(function)));
164 template <concepts::formattable_iteration_parameter_value Value>
165 auto append(std::string label,
const Value Algorithm::* ptr)
183 auto append(std::string label, Function&& function)
186 std::decay_t<Function>>>* {
189 std::decay_t<Function>>(std::forward<Function>(function)));
316 buffer.push_back(
' ');
317 param->format_label_to(buffer);
328 buffer.push_back(
' ');
329 param->format_value_to(buffer);
340 fmt::memory_buffer& buffer, Algorithm* algorithm)
const {
342 buffer.push_back(
' ');
343 param->format_value_to(buffer, algorithm);
353 buffer.append(std::string_view(
"Finished iterations: "));
354 bool is_first =
true;
359 buffer.push_back(
',');
360 buffer.push_back(
' ');
362 param->format_summary_to(buffer);
373 fmt::memory_buffer& buffer, Algorithm* algorithm)
const {
374 buffer.append(std::string_view(
"Finished iterations: "));
375 bool is_first =
true;
380 buffer.push_back(
',');
381 buffer.push_back(
' ');
383 param->format_summary_to(buffer, algorithm);
406 std::vector<std::shared_ptr<iteration_parameter_base<Algorithm>>>
Class of parameters values in iterations specified by functions.
Class to write logs of iterations.
void format_summary_to(fmt::memory_buffer &buffer) const
Format a line of summary.
log_tag_view tag_
Log tag.
auto should_write_iteration() -> bool
Determine whether to write an iteration to the logger.
void format_values_to(fmt::memory_buffer &buffer, Algorithm *algorithm) const
Format a line of values.
auto append(std::string label, Function &&function) -> iteration_parameter< Algorithm, Value, function_iteration_parameter_value< Algorithm, Value, std::decay_t< Function > > > *
Append a parameter specified by functions.
sinks::log_sink sink_
Log sink.
void write_iteration(util::source_info_view source=util::source_info_view())
Write an iteration to the logger.
fmt::memory_buffer buffer_
Buffer of logging data.
void write_iteration(Algorithm *algorithm, util::source_info_view source=util::source_info_view())
Write an iteration to the logger.
void write_label_if_needed(util::source_info_view source)
Write labels if needed.
bool write_iterations_
Whether to write iteration logs.
auto append(std::string label, const Value &value) -> iteration_parameter< Algorithm, Value, variable_iteration_parameter_value< Algorithm, Value > > *
Append a parameter specified by variables.
std::vector< std::shared_ptr< iteration_parameter_base< Algorithm > > > parameters_
Parameters.
void format_labels_to(fmt::memory_buffer &buffer) const
Format a line of labels.
void write_summary(Algorithm *algorithm, util::source_info_view source=util::source_info_view())
Write a summary to a logger.
auto append(std::string label, const Value Algorithm::*ptr) -> iteration_parameter< Algorithm, Value, member_variable_iteration_parameter_value< Algorithm, Value > > *
Append a parameter specified by member variables.
bool write_summaries_
Whether to write summary logs.
iteration_logger(logger &logger)
Constructor.
util::iteration_period_checker iteration_label_period_checker_
Checker of periods to write labels of iteration logs.
auto append(std::string label, Function &&function) -> iteration_parameter< Algorithm, Value, member_function_iteration_parameter_value< Algorithm, Value, std::decay_t< Function > > > *
Append a parameter specified by member functions.
void write_summary(util::source_info_view source=util::source_info_view())
Write a summary to a logger.
auto append(std::string label, ParameterValue value) -> iteration_parameter< Algorithm, Value, ParameterValue > *
Append a parameter.
void append(std::shared_ptr< iteration_parameter_base< Algorithm > > parameter)
Append a parameter.
util::iteration_period_checker iteration_output_period_checker_
Checker of periods to write iteration logs.
void format_summary_to(fmt::memory_buffer &buffer, Algorithm *algorithm) const
Format a line of summary.
void format_values_to(fmt::memory_buffer &buffer) const
Format a line of values.
void start(logger &logger)
Start iterations.
Base class of parameters in iterations.
Class of parameters in iterations.
Class of parameters values in iterations specified by member functions.
Class of parameters values in iterations specified by member variables.
Class of parameters values in iterations specified by variables.
Class of tags of logs without memory management.
constexpr auto name() const noexcept -> std::string_view
Get the name of this tag.
auto should_log(log_level level) const noexcept -> bool
Check whether to write logs with a log level.
void write(time_stamp time, std::string_view tag, log_level level, util::source_info_view source, std::string_view body) const noexcept
Write a log.
static auto now() noexcept -> time_stamp
Get the current time stamp.
Class to check periods of iterations.
void reset() noexcept
Reset the counter.
Class to hold information of source codes.
Concept of getter functions.
Concept of parameters values in iterations.
Concept of getter functions.
Definition of function_iteration_parameter_value class.
Definition of getter_of class.
Definition of iteration_parameter class.
Definition of iteration_parameter_value concept.
Definition of iteration_period_checker class.
Definition of log_level enumeration.
Definition of log_sink class.
Definition of log_tag_config class.
Definition of log_tag_view class.
Definition of logger class.
Definition of member_function_iteration_parameter_value class.
Definition of member_getter_of class.
Definition of member_variable_iteration_parameter_value class.
Namespace of iteration logs.
@ iteration_label
Label of iterations.
Definition of source_info_view class.
Definition of time_stamp class.
Definition of variable_iteration_parameter_value class.