mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-05-31 17:53:59 +00:00
Misc updates
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @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_
|
||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_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<LogEntry>& channel_;
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||
|
||||
#include <optional>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#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_
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "services/logging/logger.h"
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "data_model/models.h"
|
||||
#include "services/logging/logger.h"
|
||||
|
||||
std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
||||
std::shared_ptr<ILogger> logger) {
|
||||
std::optional<ApplicationOptions> ParseArguments(
|
||||
const int argc, char** argv, std::shared_ptr<ILogger> logger) {
|
||||
prog_opts::options_description desc("Pipeline Options");
|
||||
auto opt = desc.add_options();
|
||||
|
||||
@@ -70,10 +71,12 @@ std::optional<ApplicationOptions> 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<ApplicationOptions> 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<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
||||
options.pipeline.output_path = var_map["output"].as<std::string>();
|
||||
options.pipeline.log_path = var_map["log-path"].as<std::string>();
|
||||
options.pipeline.prompt_dir = var_map["prompt-dir"].as<std::string>();
|
||||
options.pipeline.location_count =
|
||||
var_map["location-count"].as<uint32_t>();
|
||||
options.pipeline.location_count = var_map["location-count"].as<uint32_t>();
|
||||
|
||||
const bool use_mocked = var_map["mocked"].as<bool>();
|
||||
const std::string model_path = var_map["model"].as<std::string>();
|
||||
@@ -111,7 +113,9 @@ std::optional<ApplicationOptions> 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<ApplicationOptions> 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<ApplicationOptions> 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<ApplicationOptions> 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<ApplicationOptions> 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;
|
||||
}
|
||||
|
||||
@@ -16,4 +16,4 @@
|
||||
LogProducer::LogProducer(BoundedChannel<LogEntry>& channel)
|
||||
: channel_(channel) {}
|
||||
|
||||
void LogProducer::Log(const LogEntry& entry) { channel_.Send(entry); }
|
||||
void LogProducer::Log(LogEntry entry) { channel_.Send(std::move(entry)); }
|
||||
|
||||
Reference in New Issue
Block a user