3#include "pixelbullet/logging/log.h"
4#include "pixelbullet/logging/log_paths.h"
13#include <unordered_map>
15namespace pixelbullet::logging_internal
17using SystemClock = std::chrono::system_clock;
18using SteadyClock = std::chrono::steady_clock;
32 explicit TextFileSink(
const std::filesystem::path& path);
38 std::ofstream stream_;
39 std::filesystem::path path_;
46 explicit NdjsonSink(
const std::filesystem::path& path);
52 std::ofstream stream_;
53 std::filesystem::path path_;
59 std::string started_at;
61 uint32_t process_id = 0;
62 bool used_environment_override =
false;
63 std::string binary_stem;
64 std::filesystem::path binary_path;
65 std::filesystem::path current_working_directory;
66 std::filesystem::path log_root;
67 std::filesystem::path session_directory;
68 std::filesystem::path latest_manifest_path;
69 std::filesystem::path session_log_path;
70 std::filesystem::path core_log_path;
71 std::filesystem::path client_log_path;
72 std::filesystem::path validation_log_path;
73 std::filesystem::path events_ndjson_path;
74 std::string client_name;
75 std::string client_version;
76 std::string engine_name;
77 std::string engine_version;
83 bool initialized =
false;
87 SteadyClock::time_point start_steady = SteadyClock::now();
88 std::shared_ptr<ConsoleSink> console;
89 std::shared_ptr<TextFileSink> session_sink;
90 std::shared_ptr<TextFileSink> core_sink;
91 std::shared_ptr<TextFileSink> client_sink;
92 std::shared_ptr<TextFileSink> validation_sink;
93 std::shared_ptr<NdjsonSink> ndjson;
94 std::unordered_map<std::string, std::shared_ptr<log::Logger>> loggers;
100 std::filesystem::path session_metadata_path;
101 std::filesystem::path latest_manifest_path;
104enum class LatestManifestWrite
110[[nodiscard]] LoggingState& GetState();
111[[nodiscard]] std::shared_ptr<log::Logger> GetOrCreateLogger(LoggingState& state, std::string_view name);
112[[nodiscard]] MetadataSnapshot MakeMetadataSnapshot(
const LoggingState& state);
114[[nodiscard]] std::string EscapeJson(std::string_view value);
115[[nodiscard]] std::string JsonString(std::string_view value);
116[[nodiscard]] std::string JsonPath(
const std::filesystem::path& path);
117[[nodiscard]] std::string JsonOptionalString(
const std::string& value);
118[[nodiscard]] std::string FormatIso8601(SystemClock::time_point time_point);
119[[nodiscard]] std::string FormatElapsed(SteadyClock::duration duration);
120[[nodiscard]] std::string ThreadIdToString();
121[[nodiscard]]
bool logger_matches_namespace(std::string_view value, std::string_view logger_namespace);
122[[nodiscard]] std::string FormatTextRecord(
const log::LogRecord& record);
123[[nodiscard]] std::string FormatNdjsonRecord(
const log::LogRecord& record);
125void PersistMetadata(
const MetadataSnapshot& snapshot, LatestManifestWrite latest_manifest_write);
126[[nodiscard]]
bool EnsureDirectoryExists(
const std::filesystem::path& path);
127[[nodiscard]]
log::LogRecord BuildRecord(
const LoggingState& state, std::string_view logger_name, log::Level level, std::string message);
129void EmitRecord(
const log::LogRecord& record,
const std::shared_ptr<ConsoleSink>& console_sink,
130 const std::shared_ptr<TextFileSink>& session_sink,
const std::shared_ptr<TextFileSink>& core_sink,
131 const std::shared_ptr<TextFileSink>& client_sink,
const std::shared_ptr<TextFileSink>& validation_sink,
132 const std::shared_ptr<NdjsonSink>& ndjson);
Definition log_internal.h:21
Definition log_paths.h:11
Definition log_internal.h:81