StormByte-Logger 3.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
45#include <StormByte/safe/optional.hxx>
46#include <StormByte/safe/string.hxx>
47#include <StormByte/type_traits/safe.hxx>
48
49#include <cstddef>
50#include <string_view>
51
56namespace StormByte::Logger {
57 class Log;
58
68
87
95
102 inline GroupManip group(const char* name) {
103 return GroupManip{StormByte::Safe::String{name != nullptr ? name : ""}};
104 }
105
112 inline GroupManip group(std::string_view name) {
114 }
115
122 return GroupManip{name};
123 }
124
136
145 inline ComponentManip component(const char* name) {
146 return ComponentManip{StormByte::Safe::String{name != nullptr ? name : ""}};
147 }
148
155 inline ComponentManip component(std::string_view name) {
157 }
158
165 return ComponentManip{name};
166 }
167
175
181
189
195
203
209
216 inline FormatManip push_format(const char* format) {
217 return FormatManip{StormByte::Safe::String{format != nullptr ? format : ""}};
218 }
219
226 inline FormatManip push_format(std::string_view format) {
227 return FormatManip{StormByte::Safe::String{format}};
228 }
229
236 return FormatManip{format};
237 }
238
242 inline constexpr PopFormatManip pop_format{};
243
250
256 constexpr ColorManip operator()(Color selected) const noexcept {
257 return ColorManip{selected};
258 }
259 };
260
264 inline const ColorManip color{};
265
271
275 inline constexpr NoColorManip nocolor{};
276
296 std::size_t count = 0;
297 bool keep_first = false;
298
304 constexpr RedactManip operator()(std::size_t n) const noexcept {
305 return RedactManip{ n, false };
306 }
307 };
308
313 inline constexpr RedactManip redact{};
314
320 constexpr RedactManip redact_first(std::size_t n) noexcept {
321 return RedactManip{ n, true };
322 }
323
347 std::size_t columns = 16;
348
354 constexpr HexManip operator()(std::size_t n) const noexcept {
355 return HexManip{ n };
356 }
357 };
358
362 inline constexpr HexManip hex{};
363
369
373 inline constexpr NoHexManip nohex{};
374
381
388
395
402}
403
Public streaming facade for the StormByte logger.
Definition log.hxx:114
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Logger::Exception)
Logger module of the StormByte suite.
FormatManip push_format(const char *format)
Save the current format and activate a temporary format.
Definition manipulators.hxx:216
constexpr HexManip hex
Enable hex dumps with 16 bytes per row.
Definition manipulators.hxx:362
ThrottlePolicy
Count policy applied before the optional rate bucket.
Definition manipulators.hxx:63
@ Drop
Admit while the rate bucket has credit.
Definition manipulators.hxx:64
@ Sample
Admit the first and then one line of every sample period.
Definition manipulators.hxx:65
@ Window
Admit the first WindowKeep lines of every WindowPeriod.
Definition manipulators.hxx:66
constexpr RedactManip redact_first(std::size_t n) noexcept
Build a manipulator that keeps the first n characters visible.
Definition manipulators.hxx:320
constexpr RedactManip redact
Full redaction manipulator (mask everything).
Definition manipulators.hxx:313
const ColorManip color
Restore the configured color for the current level.
Definition manipulators.hxx:264
ComponentManip component(const char *name)
Select the component associated with subsequent log lines on this thread.
Definition manipulators.hxx:145
constexpr NoHexManip nohex
Disable hex dumps for subsequent payloads.
Definition manipulators.hxx:373
Log & noredact(Log &log) noexcept
Disable redaction until the next redact / redact(n) / redact_first(n).
constexpr NoColorManip nocolor
Disable color for subsequent content in the current line.
Definition manipulators.hxx:275
Log & nohumanreadable(Log &log) noexcept
Disable human-readable formatting (raw numbers).
Color
ANSI foreground colors supported by the logger.
Definition typedefs.hxx:60
constexpr ResetComponentManip reset_component
Clear the current thread's component.
Definition manipulators.hxx:180
constexpr PopFormatManip pop_format
Restore the most recently saved format, or do nothing if empty.
Definition manipulators.hxx:242
Log & humanreadable_number(Log &log) noexcept
Enable human-readable formatting for numeric values.
Log & humanreadable_bytes(Log &log) noexcept
Enable human-readable formatting for byte counts.
GroupManip group(const char *name)
Set the producer group for the current line.
Definition manipulators.hxx:102
constexpr PopComponentManip pop_component
Pop one component segment from the current thread's stack.
Definition manipulators.hxx:194
Temporarily selects a configured or explicit content color.
Definition manipulators.hxx:248
StormByte::Safe::Optional< Color > value
Explicit color, or empty for the configured level color.
Definition manipulators.hxx:249
constexpr ColorManip operator()(Color selected) const noexcept
Select an explicit color for subsequent content.
Definition manipulators.hxx:256
Selects the sticky component for the current thread.
Definition manipulators.hxx:133
StormByte::Safe::String name
Component name; empty selects the root component.
Definition manipulators.hxx:134
Temporarily replaces the logger format and saves the previous one.
Definition manipulators.hxx:200
StormByte::Safe::String format
Temporary format, including an empty format if requested.
Definition manipulators.hxx:201
Labels the current logging line with a producer group.
Definition manipulators.hxx:92
StormByte::Safe::String name
Group name; an empty name clears the current group.
Definition manipulators.hxx:93
Dump subsequent payloads as hex bytes until nohex.
Definition manipulators.hxx:346
constexpr HexManip operator()(std::size_t n) const noexcept
Build a manipulator with n bytes per row.
Definition manipulators.hxx:354
std::size_t columns
Bytes per row; 0 = single line.
Definition manipulators.hxx:347
Disables color for subsequent content until changed.
Definition manipulators.hxx:270
Disable hex dumps and restore default payload formatting.
Definition manipulators.hxx:368
Pops one segment from the current thread's component stack.
Definition manipulators.hxx:188
Restores the most recently saved logger format.
Definition manipulators.hxx:208
Stateful redaction manipulator.
Definition manipulators.hxx:295
bool keep_first
true = keep first N, false = keep last N characters
Definition manipulators.hxx:297
std::size_t count
0 = mask all; N = keep N characters
Definition manipulators.hxx:296
constexpr RedactManip operator()(std::size_t n) const noexcept
Build a manipulator that keeps the last n characters visible.
Definition manipulators.hxx:304
Clears the component associated with the current thread.
Definition manipulators.hxx:174
Immutable rule description used by Log::Throttle.
Definition manipulators.hxx:76
StormByte::Safe::Optional< StormByte::Safe::String > Component
Optional component selector.
Definition manipulators.hxx:77
std::size_t SampleN
Sample period when Policy is Sample.
Definition manipulators.hxx:83
std::size_t WindowKeep
Kept lines when Policy is Window.
Definition manipulators.hxx:84
double Rate
Lines per second; zero disables refill.
Definition manipulators.hxx:80
std::size_t Burst
Initial and maximum token capacity.
Definition manipulators.hxx:81
StormByte::Safe::Optional< StormByte::Logger::Level > Level
Optional level selector.
Definition manipulators.hxx:78
std::size_t WindowPeriod
Window size when Policy is Window.
Definition manipulators.hxx:85
ThrottlePolicy Policy
Count policy.
Definition manipulators.hxx:82
StormByte::Safe::Optional< StormByte::Safe::String > Group
Optional group selector.
Definition manipulators.hxx:79
#define STORMBYTE_LOGGER_PUBLIC
Definition visibility.h:53