43#include <StormByte/byte_size.hxx>
46#include <StormByte/safe/binary.hxx>
47#include <StormByte/safe/callback.hxx>
48#include <StormByte/safe/clonable.hxx>
49#include <StormByte/safe/map.hxx>
50#include <StormByte/safe/optional.hxx>
51#include <StormByte/safe/string.hxx>
52#include <StormByte/safe/vector.hxx>
53#include <StormByte/safe/wstring.hxx>
54#include <StormByte/size.hxx>
55#include <StormByte/type_traits.hxx>
56#include <StormByte/type_traits/safe.hxx>
80 inline void OStreamWrite(
void* context,
const char* data, std::size_t size) {
81 if (context ==
nullptr || data ==
nullptr || size == 0)
83 static_cast<std::ostream*
>(context)->write(data,
static_cast<std::streamsize
>(size));
91 inline void OStreamManip(
void* context, std::ostream& (*manip)(std::ostream&)) {
92 if (context ==
nullptr || manip ==
nullptr)
94 *
static_cast<std::ostream*
>(context) << manip;
394 template <typename T>
395 inline
Log& operator<<(const T& v)
469 Write(
static_cast<std::wstring_view
>(v));
493 Write(
static_cast<std::span<const std::byte>
>(v));
505 const std::string text =
static_cast<std::string
>(v);
518 const std::string text =
static_cast<std::string
>(v);
529 template <
typename T>
533 return *
this << *value;
534 return *
this <<
"(empty Safe::Optional)";
543 template <
typename T>
547 bool first_value =
true;
548 for (
const auto& value : values) {
564 template <
typename Key,
typename Value>
568 if (!values.
empty()) {
570 bool first_entry =
true;
571 for (
const auto& entry : values) {
574 *
this <<
"\t" << entry.first <<
": " << entry.second;
779 template <typename T>
804 virtual
void Write(const
wchar_t* v);
926 template<typename Ptr>
939 template <typename Ptr, typename T>
940 Ptr& operator<<(Ptr& logger, const T& value) noexcept
954 template <
typename Ptr>
972 template <
typename Ptr>
973 Ptr&
operator<<(Ptr& logger, std::ostream& (*manip)(std::ostream&))
noexcept
Public streaming facade for the StormByte logger.
Definition log.hxx:114
Log & operator<<(std::span< const std::byte > v)
Stream raw bytes.
Definition log.hxx:478
bool LineAdmitted() const noexcept
Whether the decided current line is admitted.
virtual void Write(std::wstring_view v)
Forward wide text.
Log & operator<<(const StormByte::Safe::Binary &v)
Stream owned bytes.
Definition log.hxx:490
Log & operator<<(PopComponentManip manip)
Pop one component segment from the current thread's stack.
Definition log.hxx:707
Log & operator<<(const std::string &v)
Stream caller-owned narrow text without passing its std::string object across the DLL boundary.
Definition log.hxx:418
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:502
Log(SinkFunction &&callback, const Level &level=Level::Info, std::string_view format="[%L] %T")
Construct a Log that emits through a typed creator-owned callback.
Log & operator<<(RedactManip m)
Apply redaction policy.
Definition log.hxx:617
bool LineDecided() const noexcept
Whether throttle has already decided the current line.
Log & operator<<(FormatManip manip)
Save the current format and activate a temporary format.
Definition log.hxx:667
Log & operator<<(NoHexManip m)
Disable hex dumps.
Definition log.hxx:637
bool HasOpenOutputLine() const noexcept
Whether output has already started for the current line.
StormByte::Safe::Shared< Engine > m_engine
Shared backend on Base's heap.
Definition log.hxx:735
Log & operator<<(ComponentManip manip)
Push a component segment onto the current thread's stack.
Definition log.hxx:697
PointerType Move() override
Move this facade into a StormByte::Safe::Shared.
Log & operator<<(std::wstring_view v)
Stream wide text.
Definition log.hxx:442
friend Log & humanreadable_bytes(Log &log) noexcept
Enable human-readable formatting for byte counts.
Log & operator<<(ResetComponentManip manip)
Clear the current thread's component stack.
Definition log.hxx:717
PointerType Clone() const override
Deep-copy this facade into a StormByte::Safe::Shared.
friend Log & humanreadable_number(Log &log) noexcept
Enable human-readable formatting for numeric values.
Log & operator<<(const StormByte::Safe::WString &v)
Stream owned wide text.
Definition log.hxx:466
friend Log & noredact(Log &log) noexcept
Disable redaction until the next redact / redact(n) / redact_first(n).
Log(StormByte::Safe::Callback &&callback, const Level &level=Level::Info, std::string_view format="[%L] %T")
Construct a Log that emits text through a Base-owned callback.
bool Enabled(const Level &level) const noexcept
Whether level would be emitted given the print floor.
Log(Log &&) noexcept=default
Move constructor.
Log & operator<<(ColorManip manip)
Apply a configured or explicit content color.
Definition log.hxx:647
Log & operator<<(PopFormatManip manip)
Restore the most recently saved format.
Definition log.hxx:677
Log & operator<<(const StormByte::Safe::String &v)
Stream owned UTF-8 text.
Definition log.hxx:430
Log & operator<<(GroupManip manip)
Set the producer group for the current line.
Definition log.hxx:687
Log & operator<<(std::ostream &(*manip)(std::ostream &))
Apply a stream manipulator (e.g.
Definition log.hxx:597
Log & operator<<(const wchar_t *v)
Stream a wide C string.
Definition log.hxx:454
virtual bool BeginPayload()
Admit a numeric or narrow-text payload.
StormByte::Safe::String m_scope_path
Sticky component path; empty = root facade.
Definition log.hxx:736
Log & operator<<(Log &(*manip)(Log &) noexcept)
Apply a Log manipulator.
Definition log.hxx:607
void WriteValue(const T &v)
Forward a payload after BeginPayload.
virtual Log & FlushThrottle()
Flush dropped summaries for all throttle rules.
bool WillWrite() const noexcept
Whether the current line level will be written.
friend Log & nohumanreadable(Log &log) noexcept
Disable human-readable formatting (raw numbers).
virtual Log & Color(const Level &level, const StormByte::Logger::Color &color)
Set the configured color for a logging level.
Log & operator<<(const StormByte::ByteSize &v)
Stream an octet count.
Definition log.hxx:515
Log & operator<<(HexManip m)
Dump subsequent payloads as hex bytes until nohex.
Definition log.hxx:627
PointerType Scope(std::string_view path)
Another facade on the same backend, with a sticky component path.
virtual Log & NoThrottle(const ThrottleSpec &spec)
Remove a throttle rule with the same selectors.
StormByte::Safe::Clonable< Log >::PointerType PointerType
Owner returned by Clone, Move and Scope.
Definition log.hxx:124
bool PrepareLine()
Decide throttle admission before a payload claims a line lock.
Log & operator<<(NoColorManip manip)
Disable color for subsequent content.
Definition log.hxx:657
virtual Log & Throttle(const ThrottleSpec &spec)
Install a throttle rule.
Log & operator<<(const StormByte::Safe::Vector< T > &values)
Stream Safe vector values in bracketed, comma-separated form.
Definition log.hxx:545
Log(const Log &)=default
Copy constructor.
Log & operator<<(const StormByte::Safe::Map< Key, Value > &values)
Stream Safe map entries on separate, indented lines.
Definition log.hxx:566
Log & operator<<(const StormByte::Safe::Optional< T > &value)
Stream a Safe optional value, or a marker when it is empty.
Definition log.hxx:531
Log(std::ostream &out, const Level &level=Level::Info, std::string_view format="[%L] %T")
Construct a Log writing to out.
Definition log.hxx:135
Log & operator<<(const Level &level)
Set the level of the current line.
Definition log.hxx:587
virtual Log & Format(std::string_view format)
Set the header format.
bool empty() const noexcept
bool has_value() const noexcept
Pointer-like owner of Log or a derived logger.
Definition log.hxx:927
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Logger::Exception)
Logger module of the StormByte suite.
void(*)(void *context, std::ostream &(*manip)(std::ostream &)) SinkManip
Caller-side application of an std::ostream manipulator.
Definition typedefs.hxx:130
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:80
ThrottlePolicy
Count policy applied before the optional rate bucket.
Definition manipulators.hxx:63
StormByte::Safe::Function< void(const StormByte::Safe::String &)> SinkFunction
Typed text callback whose context is released in its creator module.
Definition typedefs.hxx:135
const ColorManip color
Restore the configured color for the current level.
Definition manipulators.hxx:264
Level
Severity levels used by the logger.
Definition typedefs.hxx:89
@ Info
Informational messages.
Definition typedefs.hxx:94
ComponentManip component(const char *name)
Select the component associated with subsequent log lines on this thread.
Definition manipulators.hxx:145
void(*)(void *context, const char *data, std::size_t size) SinkWrite
Caller-side write of raw bytes into the sink.
Definition typedefs.hxx:122
Ptr & operator<<(Ptr &logger, const T &value) noexcept
Stream a value into a smart pointer to Log or a derived logger.
Definition log.hxx:940
void OStreamManip(void *context, std::ostream &(*manip)(std::ostream &))
Apply an std::ostream manipulator in the caller's module.
Definition log.hxx:91
GroupManip group(const char *name)
Set the producer group for the current line.
Definition manipulators.hxx:102
Temporarily selects a configured or explicit content color.
Definition manipulators.hxx:248
Selects the sticky component for the current thread.
Definition manipulators.hxx:133
Labels the current logging line with a producer group.
Definition manipulators.hxx:92
Dump subsequent payloads as hex bytes until nohex.
Definition manipulators.hxx:346
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
Stateful redaction manipulator.
Definition manipulators.hxx:295
Clears the component associated with the current thread.
Definition manipulators.hxx:174
Immutable rule description used by Log::Throttle.
Definition manipulators.hxx:76
#define STORMBYTE_LOGGER_PUBLIC
Definition visibility.h:53