ORE Studio 0.0.4
Loading...
Searching...
No Matches
macros.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_TELEMETRY_LOG_MACROS_HPP
21#define ORES_TELEMETRY_LOG_MACROS_HPP
22
23#include <boost/log/sources/record_ostream.hpp>
24#include <boost/log/attributes/constant.hpp>
25#include "ores.logging/boost_severity.hpp"
26#include "ores.telemetry/domain/telemetry_context.hpp"
27
28namespace ores::telemetry::log {
29
38
40 : ctx(c) {}
41};
42
46template<typename StreamT>
47inline StreamT& operator<<(StreamT& strm, const trace_context_injector& injector) {
48 strm << boost::log::add_value("trace_id",
49 injector.ctx.get_trace_id().to_hex());
50 strm << boost::log::add_value("span_id",
51 injector.ctx.get_span_id().to_hex());
52 return strm;
53}
54
55}
56
73#define TLOG_SEV(logger, ctx, sev) \
74 BOOST_LOG_SEV(logger, ::ores::logging::boost_severity::sev) \
75 << ::ores::logging::trace_context_injector(ctx)
76
77#endif
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:32
StreamT & operator<<(StreamT &strm, const trace_context_injector &injector)
Stream operator to inject trace context into Boost.Log record.
Definition macros.hpp:47
std::string to_hex() const
Converts the span_id to a 16-character lowercase hex string.
Definition span_id.cpp:33
Immutable context passed through the call chain for telemetry.
Definition telemetry_context.hpp:50
const span_id & get_span_id() const
Gets the span_id from the current context.
Definition telemetry_context.cpp:56
const trace_id & get_trace_id() const
Gets the trace_id from the current context.
Definition telemetry_context.cpp:52
std::string to_hex() const
Converts the trace_id to a 32-character lowercase hex string.
Definition trace_id.cpp:33
Helper to add trace context attributes to a log record.
Definition macros.hpp:36