SPB Git

spb/wp40_uqo

Public MIT
1.2 KB · 29 lines cpp
1// Minimal structured logger (key=value pairs, levels, secret redaction). No external dependency.2#pragma once3#include <string>4#include <string_view>5#include <vector>6#include <utility>7#include <functional>8#include <mutex>910namespace raid::log {1112enum class Level : int { trace = 0, debug = 1, info = 2, warn = 3, error = 4, off = 5 };13using Fields = std::vector<std::pair<std::string, std::string>>;14using Sink = std::function<void(Level, std::string_view msg, const Fields&)>;1516void set_level(Level l);17Level level();18void set_sink(Sink s);  // default: stderr, one line per event, "level msg k=v k=v"19void emit(Level l, std::string_view msg, Fields fields = {});20/// Replaces bearer tokens / api keys ("fd_xxx.yyy", "Bearer …") by "<redacted>".21std::string redact(std::string_view s);2223inline void info(std::string_view m, Fields f = {}) { emit(Level::info, m, std::move(f)); }24inline void warn(std::string_view m, Fields f = {}) { emit(Level::warn, m, std::move(f)); }25inline void error(std::string_view m, Fields f = {}) { emit(Level::error, m, std::move(f)); }26inline void debug(std::string_view m, Fields f = {}) { emit(Level::debug, m, std::move(f)); }2728}  // namespace raid::log29
Files · f82ea5cc1b8ea301bc056ee35ba9c755df76f43f
Menu

Theme