From e251e7b2a33ce7c57adc04d6c256ed52a458df17 Mon Sep 17 00:00:00 2001 From: Aaron Po Date: Wed, 20 May 2026 01:53:08 -0400 Subject: [PATCH] Misc updates --- .../includes/services/logging/log_entry.h | 12 +++- .../includes/services/logging/log_producer.h | 3 +- .../includes/services/logging/logger.h | 31 +++++----- .../application_options/parse_arguments.cc | 61 +++++++++++-------- .../src/services/logging/log_producer.cc | 2 +- 5 files changed, 62 insertions(+), 47 deletions(-) diff --git a/tooling/pipeline/includes/services/logging/log_entry.h b/tooling/pipeline/includes/services/logging/log_entry.h index aa6e50c..9c8e09e 100644 --- a/tooling/pipeline/includes/services/logging/log_entry.h +++ b/tooling/pipeline/includes/services/logging/log_entry.h @@ -10,8 +10,10 @@ #define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_ #include -#include +#include #include +#include +#include /** * @enum LogLevel @@ -53,6 +55,12 @@ struct LogEntry { std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now(); + /// @brief Source location where the log call was made. + std::source_location origin = std::source_location::current(); + + /// @brief Thread responsible for emitting the log. + std::thread::id thread_id = std::this_thread::get_id(); + /// @brief Severity level of this entry. LogLevel level; @@ -65,4 +73,4 @@ struct LogEntry { }; -#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_ \ No newline at end of file +#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_ diff --git a/tooling/pipeline/includes/services/logging/log_producer.h b/tooling/pipeline/includes/services/logging/log_producer.h index f9eb941..fb769ac 100644 --- a/tooling/pipeline/includes/services/logging/log_producer.h +++ b/tooling/pipeline/includes/services/logging/log_producer.h @@ -43,8 +43,7 @@ class LogProducer final : public ILogger { * * Blocks while the channel applies backpressure. */ - void Log(LogLevel level, PipelinePhase phase, - std::string_view message) override; + void Log(LogEntry log_entry) override; private: BoundedChannel& channel_; diff --git a/tooling/pipeline/includes/services/logging/logger.h b/tooling/pipeline/includes/services/logging/logger.h index c2bd78b..5303106 100644 --- a/tooling/pipeline/includes/services/logging/logger.h +++ b/tooling/pipeline/includes/services/logging/logger.h @@ -9,9 +9,9 @@ #ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_ #define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_ -#include +#include #include -#include +#include #include "services/logging/log_entry.h" @@ -24,22 +24,19 @@ */ class ILogger { public: - ILogger() = default; - ILogger(const ILogger&) = delete; - ILogger& operator=(const ILogger&) = delete; - ILogger(ILogger&&) = delete; - ILogger& operator=(ILogger&&) = delete; - virtual ~ILogger() = default; + ILogger() = default; + ILogger(const ILogger&) = delete; + ILogger& operator=(const ILogger&) = delete; + ILogger(ILogger&&) = delete; + ILogger& operator=(ILogger&&) = delete; + virtual ~ILogger() = default; - /** - * @brief Submit a log message to the logging subsystem. - * - * @param level Severity of the message. - * @param phase Pipeline execution phase associated with the message. - * @param message Log message text. - */ - virtual void Log(LogLevel level, PipelinePhase phase, - std::string_view message) = 0; + /** + * @brief Submit a log message to the logging subsystem. + * + * @param log_entry Structured log entry data. + */ + virtual void Log(LogEntry log_entry) = 0; }; #endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_ diff --git a/tooling/pipeline/src/application_options/parse_arguments.cc b/tooling/pipeline/src/application_options/parse_arguments.cc index 5cdf0b7..00743e3 100644 --- a/tooling/pipeline/src/application_options/parse_arguments.cc +++ b/tooling/pipeline/src/application_options/parse_arguments.cc @@ -1,14 +1,15 @@ -#include "services/logging/logger.h" +#include +#include #include - #include #include #include #include "data_model/models.h" +#include "services/logging/logger.h" -std::optional ParseArguments(const int argc, char** argv, - std::shared_ptr logger) { +std::optional ParseArguments( + const int argc, char** argv, std::shared_ptr logger) { prog_opts::options_description desc("Pipeline Options"); auto opt = desc.add_options(); @@ -70,10 +71,12 @@ std::optional ParseArguments(const int argc, char** argv, return usage_stream.str(); })(); if (logger) { - logger->Log(LogLevel::Info, PipelinePhase::Startup, title); - logger->Log(LogLevel::Info, PipelinePhase::Startup, usage); - } else { - std::cout << title << std::endl << usage << std::endl; + logger->Log({.level = LogLevel::Info, + .phase = PipelinePhase::Startup, + .message = title}); + logger->Log({.level = LogLevel::Info, + .phase = PipelinePhase::Startup, + .message = usage}); } return std::nullopt; } @@ -87,9 +90,9 @@ std::optional ParseArguments(const int argc, char** argv, std::stringstream help_stream; help_stream << "\n" << desc; if (logger) { - logger->Log(LogLevel::Info, PipelinePhase::Startup, help_stream.str()); - } else { - std::cout << help_stream.str() << std::endl; + logger->Log({.level = LogLevel::Info, + .phase = PipelinePhase::Startup, + .message = help_stream.str()}); } return std::nullopt; } @@ -99,8 +102,7 @@ std::optional ParseArguments(const int argc, char** argv, options.pipeline.output_path = var_map["output"].as(); options.pipeline.log_path = var_map["log-path"].as(); options.pipeline.prompt_dir = var_map["prompt-dir"].as(); - options.pipeline.location_count = - var_map["location-count"].as(); + options.pipeline.location_count = var_map["location-count"].as(); const bool use_mocked = var_map["mocked"].as(); const std::string model_path = var_map["model"].as(); @@ -111,7 +113,9 @@ std::optional ParseArguments(const int argc, char** argv, const std::string msg = "Invalid arguments: --mocked and --model are mutually exclusive"; if (logger) { - logger->Log(LogLevel::Error, PipelinePhase::Startup, msg); + logger->Log({.level = LogLevel::Error, + .phase = PipelinePhase::Startup, + .message = msg}); } else { std::cerr << msg << std::endl; } @@ -122,7 +126,9 @@ std::optional ParseArguments(const int argc, char** argv, const std::string msg = "Invalid arguments: either --mocked or --model must be specified"; if (logger) { - logger->Log(LogLevel::Error, PipelinePhase::Startup, msg); + logger->Log({.level = LogLevel::Error, + .phase = PipelinePhase::Startup, + .message = msg}); } else { std::cerr << msg << std::endl; } @@ -135,7 +141,9 @@ std::optional ParseArguments(const int argc, char** argv, const std::string msg = "Invalid arguments: --prompt-dir is required when not using --mocked"; if (logger) { - logger->Log(LogLevel::Error, PipelinePhase::Startup, msg); + logger->Log({.level = LogLevel::Error, + .phase = PipelinePhase::Startup, + .message = msg}); } else { std::cerr << msg << std::endl; } @@ -158,11 +166,13 @@ std::optional ParseArguments(const int argc, char** argv, if (user_provided_sampling) { // Warn but do not fail — the run is still valid, the flags are just // silently irrelevant when no model is loaded. - if (use_mocked) { + if (use_mocked) { const std::string msg = "Sampling parameters are ignored when using --mocked"; if (logger) { - logger->Log(LogLevel::Warn, PipelinePhase::Startup, msg); + logger->Log({.level = LogLevel::Warn, + .phase = PipelinePhase::Startup, + .message = msg}); } else { std::cerr << msg << std::endl; } @@ -186,17 +196,18 @@ std::optional ParseArguments(const int argc, char** argv, std::string("Failed to parse command-line arguments: ") + exception.what(); if (logger) { - logger->Log(LogLevel::Error, PipelinePhase::Startup, msg); - } else { - std::cerr << msg << std::endl; + logger->Log({.level = LogLevel::Error, + .phase = PipelinePhase::Startup, + .message = msg}); } return std::nullopt; } catch (...) { - const std::string msg = "Failed to parse command-line arguments: unknown error"; + const std::string msg = + "Failed to parse command-line arguments: unknown error"; if (logger) { - logger->Log(LogLevel::Error, PipelinePhase::Startup, msg); - } else { - std::cerr << msg << std::endl; + logger->Log({.level = LogLevel::Error, + .phase = PipelinePhase::Startup, + .message = msg}); } return std::nullopt; } diff --git a/tooling/pipeline/src/services/logging/log_producer.cc b/tooling/pipeline/src/services/logging/log_producer.cc index 6c24069..9c0718c 100644 --- a/tooling/pipeline/src/services/logging/log_producer.cc +++ b/tooling/pipeline/src/services/logging/log_producer.cc @@ -16,4 +16,4 @@ LogProducer::LogProducer(BoundedChannel& channel) : channel_(channel) {} -void LogProducer::Log(const LogEntry& entry) { channel_.Send(entry); } +void LogProducer::Log(LogEntry entry) { channel_.Send(std::move(entry)); }