microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
extended_msg.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Jarosław Pelczar <jarek@jpelczar.com>
2//
3// SPDX-License-Identifier: BSD-2-Clause
4
5#pragma once
6
12#include "log_msg.hpp"
13#include <cstdint>
14
15namespace microfmt::log {
16
18inline constexpr std::uint32_t no_cpu = 0xFFFFFFFFU;
19
21enum class log_flag : std::uint32_t {
22 none = 0,
28 can_wait = 1U << 0,
29};
30
32struct RELOCO_COPYABLE log_meta {
34 static constexpr unsigned user_flags_shift = 16;
35
36 std::uint32_t pid{0};
37 std::uint32_t tid{0};
38 std::uint32_t cpu{no_cpu};
39 std::uint32_t flags{0};
40
41 [[nodiscard]] constexpr bool has(log_flag f) const noexcept { return (flags & static_cast<std::uint32_t>(f)) != 0; }
42 [[nodiscard]] constexpr bool can_wait() const noexcept { return has(log_flag::can_wait); }
43
45 [[nodiscard]] constexpr std::uint32_t user_flags() const noexcept { return flags >> user_flags_shift; }
46
48 constexpr void set_user_flags(std::uint32_t user) noexcept {
49 flags = (flags & 0xFFFFU) | ((user & 0xFFFFU) << user_flags_shift);
50 }
51
52 constexpr void set(log_flag f, bool on = true) noexcept {
53 const auto bit = static_cast<std::uint32_t>(f);
54 flags = on ? (flags | bit) : (flags & ~bit);
55 }
56};
57
63 log_meta meta{};
64
65 constexpr extended_log_msg() = default;
66 explicit constexpr extended_log_msg(const log_msg &base, const log_meta &m = {}) noexcept : log_msg(base), meta(m) {}
67};
68
69} // namespace microfmt::log
70
71RELOCO_TYPE_ID_NAME(microfmt::log::extended_log_msg, "microfmt::log::extended_log_msg");
#define MICROFMT_API_CLASS
Definition compat.hpp:181
RELOCO_TYPE_ID_NAME(microfmt::log::extended_log_msg, "microfmt::log::extended_log_msg")
Structured log-record types and severity levels.
Definition default_log_sink.template.hpp:51
constexpr std::uint32_t no_cpu
CPU index value meaning "unknown".
Definition extended_msg.hpp:18
log_flag
Well-known bits of log_meta::flags. Bits 16..31 belong to the user.
Definition extended_msg.hpp:21
log_msg plus log_meta. Derives from the original record, so it converts to const log_msg & anywhere t...
Definition extended_msg.hpp:62
constexpr extended_log_msg()=default
constexpr extended_log_msg(const log_msg &base, const log_meta &m={}) noexcept
Definition extended_msg.hpp:66
Execution-context metadata attached to an extended_log_msg.
Definition extended_msg.hpp:32
constexpr void set_user_flags(std::uint32_t user) noexcept
Replaces the 16 user-defined flag bits.
Definition extended_msg.hpp:48
constexpr bool can_wait() const noexcept
Definition extended_msg.hpp:42
constexpr void set(log_flag f, bool on=true) noexcept
Definition extended_msg.hpp:52
constexpr std::uint32_t user_flags() const noexcept
Returns the user-defined flag bits, shifted down to bit 0.
Definition extended_msg.hpp:45
constexpr bool has(log_flag f) const noexcept
Definition extended_msg.hpp:41
Structured log record forwarded by a logger to each sink.
Definition log_msg.hpp:69