StormByte C++ Library: Logger module 1.2.0
StormByte-Logger is the logging module of the StormByte C++ suite.
Loading...
Searching...
No Matches
manipulators.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Logger.
5 *
6 * StormByte-Logger is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Logger is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Logger. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
24
25#include <cstddef>
26#include <optional>
27#include <string>
28
33namespace StormByte::Logger {
34 class Log;
35
40 enum class STORMBYTE_LOGGER_PUBLIC ThrottlePolicy : unsigned char {
41 Drop,
42 Sample,
43 Window
44 };
45
54 std::optional<std::string> Component;
55 std::optional<Level> Level;
56 std::optional<std::string> Group;
57 double Rate = 0.0;
58 std::size_t Burst = 0;
59 ThrottlePolicy Policy = ThrottlePolicy::Drop;
60 std::size_t SampleN = 0;
61 std::size_t WindowKeep = 0;
62 std::size_t WindowPeriod = 0;
63 };
64
70 std::string name;
71 };
72
79
89 std::string name;
90 };
91
100
108
114
122
128
134 std::string format;
135 };
136
142
149
153 inline constexpr PopFormatManip pop_format{};
154
160 std::optional<Color> value;
161
167 constexpr ColorManip operator()(Color selected) const noexcept {
168 return ColorManip{selected};
169 }
170 };
171
175 inline constexpr ColorManip color{};
176
182
186 inline constexpr NoColorManip nocolor{};
187
207 std::size_t count = 0;
208 bool keep_first = false;
209
215 constexpr RedactManip operator()(std::size_t n) const noexcept {
216 return RedactManip{ n, false };
217 }
218 };
219
224 inline constexpr RedactManip redact{};
225
231 constexpr RedactManip redact_first(std::size_t n) noexcept {
232 return RedactManip{ n, true };
233 }
234
255 std::size_t columns = 16;
256
262 constexpr HexManip operator()(std::size_t n) const noexcept {
263 return HexManip{ n };
264 }
265 };
266
270 inline constexpr HexManip hex{};
271
277
281 inline constexpr NoHexManip nohex{};
282
289
296
303
310}
Public streaming facade for the StormByte logger.
Definition log.hxx:65
Logger module of the StormByte suite.
Log & nohumanreadable(Log &log) noexcept
Disable human-readable formatting (raw numbers).
constexpr HexManip hex
Enable hex dumps with 16 bytes per row.
Definition manipulators.hxx:270
Log & humanreadable_bytes(Log &log) noexcept
Enable human-readable formatting for byte counts.
ComponentManip component(std::string name)
Select the component associated with subsequent log lines on this thread.
ThrottlePolicy
Count policy applied before the optional rate bucket.
Definition manipulators.hxx:40
@ Drop
Admit while the rate bucket has credit.
@ Sample
Admit the first and then one line of every sample period.
@ Window
Admit the first WindowKeep lines of every WindowPeriod.
Log & noredact(Log &log) noexcept
Disable redaction until the next redact / redact(n) / redact_first(n).
constexpr RedactManip redact_first(std::size_t n) noexcept
Build a manipulator that keeps the first n characters visible.
Definition manipulators.hxx:231
constexpr RedactManip redact
Full redaction manipulator (mask everything).
Definition manipulators.hxx:224
GroupManip group(std::string name)
Set the producer group for the current line.
constexpr NoHexManip nohex
Disable hex dumps for subsequent payloads.
Definition manipulators.hxx:281
Log & humanreadable_number(Log &log) noexcept
Enable human-readable formatting for numeric values.
constexpr NoColorManip nocolor
Disable color for subsequent content in the current line.
Definition manipulators.hxx:186
FormatManip push_format(std::string format)
Save the current format and activate a temporary format.
Color
ANSI foreground colors supported by the logger.
Definition typedefs.hxx:37
constexpr ResetComponentManip reset_component
Clear the current thread's component.
Definition manipulators.hxx:113
constexpr PopFormatManip pop_format
Restore the most recently saved format, or do nothing if empty.
Definition manipulators.hxx:153
constexpr ColorManip color
Restore the configured color for the current level.
Definition manipulators.hxx:175
constexpr PopComponentManip pop_component
Pop one component segment from the current thread's stack.
Definition manipulators.hxx:127
Temporarily selects a configured or explicit content color.
Definition manipulators.hxx:159
std::optional< Color > value
Explicit color, or empty for the configured level color.
Definition manipulators.hxx:160
constexpr ColorManip operator()(Color selected) const noexcept
Select an explicit color for subsequent content.
Definition manipulators.hxx:167
Selects the sticky component for the current thread.
Definition manipulators.hxx:88
std::string name
Component name; empty selects the root component.
Definition manipulators.hxx:89
Temporarily replaces the logger format and saves the previous one.
Definition manipulators.hxx:133
std::string format
Temporary format, including an empty format if requested.
Definition manipulators.hxx:134
Labels the current logging line with a producer group.
Definition manipulators.hxx:69
std::string name
Group name; an empty name clears the current group.
Definition manipulators.hxx:70
Dump subsequent payloads as hex bytes until nohex.
Definition manipulators.hxx:254
constexpr HexManip operator()(std::size_t n) const noexcept
Build a manipulator with n bytes per row.
Definition manipulators.hxx:262
Disables color for subsequent content until changed.
Definition manipulators.hxx:181
Disable hex dumps and restore default payload formatting.
Definition manipulators.hxx:276
Pops one segment from the current thread's component stack.
Definition manipulators.hxx:121
Restores the most recently saved logger format.
Definition manipulators.hxx:141
Stateful redaction manipulator.
Definition manipulators.hxx:206
constexpr RedactManip operator()(std::size_t n) const noexcept
Build a manipulator that keeps the last n characters visible.
Definition manipulators.hxx:215
Clears the component associated with the current thread.
Definition manipulators.hxx:107
Immutable rule description used by Log::Throttle.
Definition manipulators.hxx:53
std::optional< Level > Level
Optional level selector.
Definition manipulators.hxx:55
std::optional< std::string > Group
Optional group selector.
Definition manipulators.hxx:56
std::optional< std::string > Component
Optional component selector.
Definition manipulators.hxx:54
#define STORMBYTE_LOGGER_PUBLIC
Definition visibility.h:28