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_
|
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOG_ENTRY_H_
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <source_location>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum LogLevel
|
* @enum LogLevel
|
||||||
@@ -53,6 +55,12 @@ struct LogEntry {
|
|||||||
std::chrono::system_clock::time_point timestamp =
|
std::chrono::system_clock::time_point timestamp =
|
||||||
std::chrono::system_clock::now();
|
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.
|
/// @brief Severity level of this entry.
|
||||||
LogLevel level;
|
LogLevel level;
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ class LogProducer final : public ILogger {
|
|||||||
*
|
*
|
||||||
* Blocks while the channel applies backpressure.
|
* Blocks while the channel applies backpressure.
|
||||||
*/
|
*/
|
||||||
void Log(LogLevel level, PipelinePhase phase,
|
void Log(LogEntry log_entry) override;
|
||||||
std::string_view message) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BoundedChannel<LogEntry>& channel_;
|
BoundedChannel<LogEntry>& channel_;
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
#ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
#ifndef BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||||
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
#define BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||||
|
|
||||||
#include <optional>
|
#include <source_location>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <utility>
|
||||||
|
|
||||||
#include "services/logging/log_entry.h"
|
#include "services/logging/log_entry.h"
|
||||||
|
|
||||||
@@ -34,12 +34,9 @@ class ILogger {
|
|||||||
/**
|
/**
|
||||||
* @brief Submit a log message to the logging subsystem.
|
* @brief Submit a log message to the logging subsystem.
|
||||||
*
|
*
|
||||||
* @param level Severity of the message.
|
* @param log_entry Structured log entry data.
|
||||||
* @param phase Pipeline execution phase associated with the message.
|
|
||||||
* @param message Log message text.
|
|
||||||
*/
|
*/
|
||||||
virtual void Log(LogLevel level, PipelinePhase phase,
|
virtual void Log(LogEntry log_entry) = 0;
|
||||||
std::string_view message) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
#endif // BIERGARTEN_PIPELINE_INCLUDES_SERVICES_LOGGING_LOGGER_H_
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
#include "services/logging/logger.h"
|
#include <chrono>
|
||||||
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "data_model/models.h"
|
#include "data_model/models.h"
|
||||||
|
#include "services/logging/logger.h"
|
||||||
|
|
||||||
std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
std::optional<ApplicationOptions> ParseArguments(
|
||||||
std::shared_ptr<ILogger> logger) {
|
const int argc, char** argv, std::shared_ptr<ILogger> logger) {
|
||||||
prog_opts::options_description desc("Pipeline Options");
|
prog_opts::options_description desc("Pipeline Options");
|
||||||
auto opt = desc.add_options();
|
auto opt = desc.add_options();
|
||||||
|
|
||||||
@@ -70,10 +71,12 @@ std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
|||||||
return usage_stream.str();
|
return usage_stream.str();
|
||||||
})();
|
})();
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Info, PipelinePhase::Startup, title);
|
logger->Log({.level = LogLevel::Info,
|
||||||
logger->Log(LogLevel::Info, PipelinePhase::Startup, usage);
|
.phase = PipelinePhase::Startup,
|
||||||
} else {
|
.message = title});
|
||||||
std::cout << title << std::endl << usage << std::endl;
|
logger->Log({.level = LogLevel::Info,
|
||||||
|
.phase = PipelinePhase::Startup,
|
||||||
|
.message = usage});
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
@@ -87,9 +90,9 @@ std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
|||||||
std::stringstream help_stream;
|
std::stringstream help_stream;
|
||||||
help_stream << "\n" << desc;
|
help_stream << "\n" << desc;
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Info, PipelinePhase::Startup, help_stream.str());
|
logger->Log({.level = LogLevel::Info,
|
||||||
} else {
|
.phase = PipelinePhase::Startup,
|
||||||
std::cout << help_stream.str() << std::endl;
|
.message = help_stream.str()});
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
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.output_path = var_map["output"].as<std::string>();
|
||||||
options.pipeline.log_path = var_map["log-path"].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.prompt_dir = var_map["prompt-dir"].as<std::string>();
|
||||||
options.pipeline.location_count =
|
options.pipeline.location_count = var_map["location-count"].as<uint32_t>();
|
||||||
var_map["location-count"].as<uint32_t>();
|
|
||||||
|
|
||||||
const bool use_mocked = var_map["mocked"].as<bool>();
|
const bool use_mocked = var_map["mocked"].as<bool>();
|
||||||
const std::string model_path = var_map["model"].as<std::string>();
|
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 =
|
const std::string msg =
|
||||||
"Invalid arguments: --mocked and --model are mutually exclusive";
|
"Invalid arguments: --mocked and --model are mutually exclusive";
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Error, PipelinePhase::Startup, msg);
|
logger->Log({.level = LogLevel::Error,
|
||||||
|
.phase = PipelinePhase::Startup,
|
||||||
|
.message = msg});
|
||||||
} else {
|
} else {
|
||||||
std::cerr << msg << std::endl;
|
std::cerr << msg << std::endl;
|
||||||
}
|
}
|
||||||
@@ -122,7 +126,9 @@ std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
|||||||
const std::string msg =
|
const std::string msg =
|
||||||
"Invalid arguments: either --mocked or --model must be specified";
|
"Invalid arguments: either --mocked or --model must be specified";
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Error, PipelinePhase::Startup, msg);
|
logger->Log({.level = LogLevel::Error,
|
||||||
|
.phase = PipelinePhase::Startup,
|
||||||
|
.message = msg});
|
||||||
} else {
|
} else {
|
||||||
std::cerr << msg << std::endl;
|
std::cerr << msg << std::endl;
|
||||||
}
|
}
|
||||||
@@ -135,7 +141,9 @@ std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
|||||||
const std::string msg =
|
const std::string msg =
|
||||||
"Invalid arguments: --prompt-dir is required when not using --mocked";
|
"Invalid arguments: --prompt-dir is required when not using --mocked";
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Error, PipelinePhase::Startup, msg);
|
logger->Log({.level = LogLevel::Error,
|
||||||
|
.phase = PipelinePhase::Startup,
|
||||||
|
.message = msg});
|
||||||
} else {
|
} else {
|
||||||
std::cerr << msg << std::endl;
|
std::cerr << msg << std::endl;
|
||||||
}
|
}
|
||||||
@@ -162,7 +170,9 @@ std::optional<ApplicationOptions> ParseArguments(const int argc, char** argv,
|
|||||||
const std::string msg =
|
const std::string msg =
|
||||||
"Sampling parameters are ignored when using --mocked";
|
"Sampling parameters are ignored when using --mocked";
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Warn, PipelinePhase::Startup, msg);
|
logger->Log({.level = LogLevel::Warn,
|
||||||
|
.phase = PipelinePhase::Startup,
|
||||||
|
.message = msg});
|
||||||
} else {
|
} else {
|
||||||
std::cerr << msg << std::endl;
|
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: ") +
|
std::string("Failed to parse command-line arguments: ") +
|
||||||
exception.what();
|
exception.what();
|
||||||
if (logger) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Error, PipelinePhase::Startup, msg);
|
logger->Log({.level = LogLevel::Error,
|
||||||
} else {
|
.phase = PipelinePhase::Startup,
|
||||||
std::cerr << msg << std::endl;
|
.message = msg});
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} catch (...) {
|
} 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) {
|
if (logger) {
|
||||||
logger->Log(LogLevel::Error, PipelinePhase::Startup, msg);
|
logger->Log({.level = LogLevel::Error,
|
||||||
} else {
|
.phase = PipelinePhase::Startup,
|
||||||
std::cerr << msg << std::endl;
|
.message = msg});
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,4 +16,4 @@
|
|||||||
LogProducer::LogProducer(BoundedChannel<LogEntry>& channel)
|
LogProducer::LogProducer(BoundedChannel<LogEntry>& channel)
|
||||||
: channel_(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