StormByte-Logger 2.0.0
C++26 logger module of the StormByte 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 original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Logger source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-String tree and
23 * the StormByte Base tree it vendors), which remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-Logger is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-Logger. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
46
47#include <cstddef>
48#include <optional>
49#include <string_view>
50
55namespace StormByte::Logger {
56 class Log;
57
62 enum class STORMBYTE_LOGGER_PUBLIC ThrottlePolicy : unsigned char {
63 Drop,
64 Sample,
65 Window
66 };
67
76 std::optional<StormByte::String::String> Component;
77 std::optional<Level> Level;
78 std::optional<StormByte::String::String> Group;
79 double Rate = 0.0;
80 std::size_t Burst = 0;
81 ThrottlePolicy Policy = ThrottlePolicy::Drop;
82 std::size_t SampleN = 0;
83 std::size_t WindowKeep = 0;
84 std::size_t WindowPeriod = 0;
85 };
86
94
101
107 inline GroupManip group(std::string_view name) {
108 return group(StormByte::String::String{name});
109 }
110
122
131
137 inline ComponentManip component(std::string_view name) {
139 }
140
148
154
162
168
176
182
189
195 inline FormatManip push_format(std::string_view format) {
197 }
198
202 inline constexpr PopFormatManip pop_format{};
203
209 std::optional<Color> value;
210
216 constexpr ColorManip operator()(Color selected) const noexcept {
217 return ColorManip{selected};
218 }
219 };
220
224 inline constexpr ColorManip color{};
225
231
235 inline constexpr NoColorManip nocolor{};
236
256 std::size_t count = 0;
257 bool keep_first = false;
258
264 constexpr RedactManip operator()(std::size_t n) const noexcept {
265 return RedactManip{ n, false };
266 }
267 };
268
273 inline constexpr RedactManip redact{};
274
280 constexpr RedactManip redact_first(std::size_t n) noexcept {
281 return RedactManip{ n, true };
282 }
283
307 std::size_t columns = 16;
308
314 constexpr HexManip operator()(std::size_t n) const noexcept {
315 return HexManip{ n };
316 }
317 };
318
322 inline constexpr HexManip hex{};
323
329
333 inline constexpr NoHexManip nohex{};
334
341
348
355
362}
Public streaming facade for the StormByte logger.
Definition log.hxx:111
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:322
Log & humanreadable_bytes(Log &log) noexcept
Enable human-readable formatting for byte counts.
GroupManip group(StormByte::String::String name)
Set the producer group for the current line.
ThrottlePolicy
Count policy applied before the optional rate bucket.
Definition manipulators.hxx:62
@ 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:280
constexpr RedactManip redact
Full redaction manipulator (mask everything).
Definition manipulators.hxx:273
constexpr NoHexManip nohex
Disable hex dumps for subsequent payloads.
Definition manipulators.hxx:333
ComponentManip component(StormByte::String::String name)
Select the component associated with subsequent log lines on this thread.
FormatManip push_format(StormByte::String::String format)
Save the current format and activate a temporary format.
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:235
Color
ANSI foreground colors supported by the logger.
Definition typedefs.hxx:58
constexpr ResetComponentManip reset_component
Clear the current thread's component.
Definition manipulators.hxx:153
constexpr PopFormatManip pop_format
Restore the most recently saved format, or do nothing if empty.
Definition manipulators.hxx:202
constexpr ColorManip color
Restore the configured color for the current level.
Definition manipulators.hxx:224
constexpr PopComponentManip pop_component
Pop one component segment from the current thread's stack.
Definition manipulators.hxx:167
Temporarily selects a configured or explicit content color.
Definition manipulators.hxx:208
std::optional< Color > value
Explicit color, or empty for the configured level color.
Definition manipulators.hxx:209
constexpr ColorManip operator()(Color selected) const noexcept
Select an explicit color for subsequent content.
Definition manipulators.hxx:216
Selects the sticky component for the current thread.
Definition manipulators.hxx:119
StormByte::String::String name
Component name; empty selects the root component.
Definition manipulators.hxx:120
Temporarily replaces the logger format and saves the previous one.
Definition manipulators.hxx:173
StormByte::String::String format
Temporary format, including an empty format if requested.
Definition manipulators.hxx:174
Labels the current logging line with a producer group.
Definition manipulators.hxx:91
StormByte::String::String name
Group name; an empty name clears the current group.
Definition manipulators.hxx:92
Dump subsequent payloads as hex bytes until nohex.
Definition manipulators.hxx:306
constexpr HexManip operator()(std::size_t n) const noexcept
Build a manipulator with n bytes per row.
Definition manipulators.hxx:314
Disables color for subsequent content until changed.
Definition manipulators.hxx:230
Disable hex dumps and restore default payload formatting.
Definition manipulators.hxx:328
Pops one segment from the current thread's component stack.
Definition manipulators.hxx:161
Restores the most recently saved logger format.
Definition manipulators.hxx:181
Stateful redaction manipulator.
Definition manipulators.hxx:255
constexpr RedactManip operator()(std::size_t n) const noexcept
Build a manipulator that keeps the last n characters visible.
Definition manipulators.hxx:264
Clears the component associated with the current thread.
Definition manipulators.hxx:147
Immutable rule description used by Log::Throttle.
Definition manipulators.hxx:75
std::optional< Level > Level
Optional level selector.
Definition manipulators.hxx:77
std::optional< StormByte::String::String > Component
Optional component selector.
Definition manipulators.hxx:76
std::optional< StormByte::String::String > Group
Optional group selector.
Definition manipulators.hxx:78
#define STORMBYTE_LOGGER_PUBLIC
Definition visibility.h:53