Example to write logs.
#include <exception>
#include <iostream>
#include <string>
#include <lyra/lyra.hpp>
static void write_logs() {
logger.info()("Example of logs with various log levels.");
}
static void write_to_default_tag() {
logger.info()("Example of logs without a log tag.");
logger, "trace");
}
static void write_iterations() {
logger.info()("Example of logs of iterations.");
auto iteration_logger =
int val1 = 0;
iteration_logger.append("val1", val1);
std::string val2;
iteration_logger.append("val2", val2);
iteration_logger.template append<double>("val3", [] {
return 1.23456;
});
val1 = 3;
val2 = "abc";
iteration_logger.write_iteration();
constexpr int repetition = 300;
iteration_logger.start(logger);
for (int i = 0; i < repetition; ++i) {
val1 = i;
iteration_logger.write_iteration();
}
iteration_logger.write_summary();
}
auto main(int argc, char** argv) -> int {
try {
std::string config_filepath;
const auto cli =
lyra::cli().add_argument(lyra::opt(config_filepath, "path")
.name("--config")
.name("-c")
.optional()
.help("Load a logging configuration file."));
const auto result = cli.parse({argc, argv});
if (!result) {
std::cerr << result.message() << "\n\n";
std::cerr << cli << std::endl;
return 1;
}
if (config_filepath.empty()) {
const auto config =
} else {
}
write_logs();
write_to_default_tag();
write_iterations();
return 0;
} catch (const std::exception& e) {
std::cerr << "Exception thrown: " << e.what() << std::endl;
return 1;
}
}
Class to write logs of iterations.
Class of tags of logs without memory management.
Definition of iteration_logger class.
Definition of load_logging_config function.
Definition of functions to get and set logging configurations.
Definition of log_level enumeration.
Definition of log_tag_config class.
Definition of log_tag_view class.
Definition of logger class.
Definition of macros for logging.
#define NUM_COLLECT_LOG_ITERATION(LOGGER,...)
Write a log of an iteration.
#define NUM_COLLECT_LOG_INFO(LOGGER,...)
Write an information log.
#define NUM_COLLECT_LOG_SUMMARY(LOGGER,...)
Write a summary log.
#define NUM_COLLECT_LOG_TRACE(LOGGER,...)
Write a trace log.
#define NUM_COLLECT_LOG_ITERATION_LABEL(LOGGER,...)
Write a log of a label of iterations.
#define NUM_COLLECT_LOG_CRITICAL(LOGGER,...)
Write a critical log.
#define NUM_COLLECT_LOG_ERROR(LOGGER,...)
Write an error log.
#define NUM_COLLECT_LOG_WARNING(LOGGER,...)
Write a warning log.
#define NUM_COLLECT_LOG_DEBUG(LOGGER,...)
Write a debug log.
NUM_COLLECT_EXPORT auto get_default_tag_config() -> log_tag_config
Get the default configuration of log tags.
NUM_COLLECT_EXPORT void load_logging_config_file(std::string_view filepath)
Parse and apply configurations of logging from a file.
NUM_COLLECT_EXPORT void set_default_tag_config(const log_tag_config &config)
Set the default configuration of log tags.