77 inline void OStreamWrite(
void* context,
const char* data, std::size_t size) {
78 if (context ==
nullptr || data ==
nullptr || size == 0)
80 static_cast<std::ostream*
>(context)->write(data,
static_cast<std::streamsize
>(size));
88 inline void OStreamManip(
void* context, std::ostream& (*manip)(std::ostream&)) {
89 if (context ==
nullptr || manip ==
nullptr)
91 *
static_cast<std::ostream*
>(context) << manip;
132 Log(std::ostream& out,
const Level& level = Level::Info, std::string_view format =
"[%L] %T")
179 bool Enabled(const
Level& level) const noexcept;
218 virtual
Log& Format(
std::string_view format);
232 virtual
Log& Format(
std::string_view component,
std::string_view format);
261 virtual
Log& Throttle(
double rate,
std::
size_t burst);
281 virtual
Log& Throttle(const
Level& level,
double rate,
std::
size_t burst);
319 virtual
Log& NoThrottle();
355 virtual
Log& FlushThrottle();
375 template <typename T>
376 inline
Log& operator<<(const T& v)
383 if (!WillWrite()) [[likely]]
386 WriteValue(
static_cast<const char*
>(v));
390 WriteValue(
static_cast<std::decay_t<T>
>(v));
400 if (!WillWrite()) [[likely]]
402 WriteValue(
static_cast<std::string_view
>(v));
412 if (!WillWrite()) [[likely]]
414 WriteValue(
static_cast<std::string_view
>(v));
424 if (!WillWrite()) [[likely]]
436 if (!WillWrite()) [[likely]]
448 if (!WillWrite()) [[likely]]
450 Write(
static_cast<std::wstring_view
>(v));
460 if (!WillWrite()) [[likely]]
462 Write(
static_cast<std::wstring_view
>(v));
472 if (!WillWrite()) [[likely]]
484 if (!WillWrite()) [[likely]]
486 Write(
static_cast<std::span<const std::byte>
>(v));
496 if (!WillWrite()) [[likely]]
498 const std::string text =
static_cast<std::string
>(v);
499 WriteValue(std::string_view{text});
509 if (!WillWrite()) [[likely]]
511 const std::string text =
static_cast<std::string
>(v);
512 WriteValue(std::string_view{text});
688 bool HasOpenOutputLine() const noexcept;
694 bool LineDecided() const noexcept;
700 bool LineAdmitted() const noexcept;
706 virtual
bool BeginPayload();
713 template <typename T>
714 void WriteValue(const T& v);
732 virtual
void Write(
std::wstring_view v);
738 virtual
void Write(const
wchar_t* v);
744 virtual
void Write(
std::span<const
std::
byte> v);
750 virtual
void Write(const
Level& level);
756 virtual
void Write(
std::ostream& (*manip)(
std::ostream&));
762 virtual
void Write(
Log& (*manip)(
Log&) noexcept);
860 template<typename Ptr>
863 &&
StormByte::
Type::DerivedFrom<typename
std::remove_cvref_t<Ptr>::element_type, Log>;
873 template <typename Ptr, typename T>
874 Ptr& operator<<(Ptr& logger, const T& value) noexcept
888 template <
typename Ptr>
906 template <
typename Ptr>
907 Ptr&
operator<<(Ptr& logger, std::ostream& (*manip)(std::ostream&))
noexcept
Public streaming facade for the StormByte logger.
Definition log.hxx:111
Log & operator<<(std::span< const std::byte > v)
Stream raw bytes.
Definition log.hxx:471
friend Log & nohumanreadable(Log &log) noexcept
Disable human-readable formatting (raw numbers).
Log & operator<<(PopComponentManip manip)
Pop one component segment from the current thread's stack.
Definition log.hxx:641
Log(SinkWrite write, SinkManip manip, void *context, const Level &level, std::string_view format)
Construct a logger that emits through caller callbacks.
Log & operator<<(const StormByte::Size &v)
Stream a byte count.
Definition log.hxx:495
Log & operator<<(const StormByte::CString &v)
Stream owned UTF-8 bytes.
Definition log.hxx:399
std::shared_ptr< Engine > m_engine
Shared backend.
Definition log.hxx:669
Log & operator<<(RedactManip m)
Apply redaction policy.
Definition log.hxx:551
Log & operator<<(FormatManip manip)
Save the current format and activate a temporary format.
Definition log.hxx:601
Log & operator<<(NoHexManip m)
Disable hex dumps.
Definition log.hxx:571
Log & operator<<(ComponentManip manip)
Push a component segment onto the current thread's stack.
Definition log.hxx:631
StormByte::Clonable< Log >::PointerType PointerType
Owner returned by Clone, Move and Scope.
Definition log.hxx:121
Log & operator<<(const StormByte::BinaryData &v)
Stream owned bytes.
Definition log.hxx:483
Log & operator<<(std::wstring_view v)
Stream wide text.
Definition log.hxx:423
Log & operator<<(ResetComponentManip manip)
Clear the current thread's component stack.
Definition log.hxx:651
friend Log & noredact(Log &log) noexcept
Disable redaction until the next redact / redact(n) / redact_first(n).
Log & operator<<(const StormByte::String::WString &v)
Stream owned wide text.
Definition log.hxx:459
Log(Log &&) noexcept=default
Move constructor.
Log & operator<<(ColorManip manip)
Apply a configured or explicit content color.
Definition log.hxx:581
Log & operator<<(PopFormatManip manip)
Restore the most recently saved format.
Definition log.hxx:611
Log & operator<<(GroupManip manip)
Set the producer group for the current line.
Definition log.hxx:621
Log & operator<<(std::ostream &(*manip)(std::ostream &))
Apply a stream manipulator (e.g.
Definition log.hxx:531
Log & operator<<(const wchar_t *v)
Stream a wide C string.
Definition log.hxx:435
Log & operator<<(Log &(*manip)(Log &) noexcept)
Apply a Log manipulator.
Definition log.hxx:541
friend Log & humanreadable_bytes(Log &log) noexcept
Enable human-readable formatting for byte counts.
StormByte::String::String m_scope_path
Sticky component path; empty = root facade.
Definition log.hxx:670
Log & operator<<(const StormByte::String::String &v)
Stream owned UTF-8 text.
Definition log.hxx:411
bool WillWrite() const noexcept
Whether the current line level will be written.
Log & operator<<(const StormByte::WCString &v)
Stream owned wide bytes.
Definition log.hxx:447
Log & operator<<(const StormByte::ByteSize &v)
Stream an octet count.
Definition log.hxx:508
Log & operator<<(HexManip m)
Dump subsequent payloads as hex bytes until nohex.
Definition log.hxx:561
Log & operator<<(NoColorManip manip)
Disable color for subsequent content.
Definition log.hxx:591
Log(const Log &)=default
Copy constructor.
friend Log & humanreadable_number(Log &log) noexcept
Enable human-readable formatting for numeric values.
Log(std::ostream &out, const Level &level=Level::Info, std::string_view format="[%L] %T")
Construct a Log writing to out.
Definition log.hxx:132
Log & operator<<(const Level &level)
Set the level of the current line.
Definition log.hxx:521
Pointer-like owner of Log or a derived logger.
Definition log.hxx:861
Logger module of the StormByte suite.
void OStreamWrite(void *context, const char *data, std::size_t size)
Write raw bytes into an std::ostream owned by the caller.
Definition log.hxx:77
ThrottlePolicy
Count policy applied before the optional rate bucket.
Definition manipulators.hxx:62
void(*)(void *context, std::ostream &(*manip)(std::ostream &)) SinkManip
Caller-side application of an std::ostream manipulator.
Definition typedefs.hxx:128
Level
Severity levels used by the logger.
Definition typedefs.hxx:87
Color
ANSI foreground colors supported by the logger.
Definition typedefs.hxx:58
void(*)(void *context, const char *data, std::size_t size) SinkWrite
Caller-side write of raw bytes into the sink.
Definition typedefs.hxx:120
void OStreamManip(void *context, std::ostream &(*manip)(std::ostream &))
Apply an std::ostream manipulator in the caller's module.
Definition log.hxx:88
std::ostream & operator<<(std::ostream &stream, ByteSize size)
Temporarily selects a configured or explicit content color.
Definition manipulators.hxx:208
Selects the sticky component for the current thread.
Definition manipulators.hxx:119
Labels the current logging line with a producer group.
Definition manipulators.hxx:91
Dump subsequent payloads as hex bytes until nohex.
Definition manipulators.hxx:306
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
Stateful redaction manipulator.
Definition manipulators.hxx:255
Clears the component associated with the current thread.
Definition manipulators.hxx:147
Immutable rule description used by Log::Throttle.
Definition manipulators.hxx:75
#define STORMBYTE_LOGGER_PUBLIC
Definition visibility.h:53