Senzing C++ SDK
C++ SDK for Senzing v4, patterned after the official C# SDK
Loading...
Searching...
No Matches
SzLogging.hpp
Go to the documentation of this file.
1// SzLogging.hpp -- Senzing native logging (libSzLogging): public types and the
2// abstract SzLogging interface.
3//
4// This API LEADS the C# SDK: C# (sz-sdk-csharp@4.3.0) has no SzLogging yet. The
5// reference design is the Rust SDK (sz-rust-sdk v4.5.0, src/logging.rs +
6// src/traits.rs); names are the C#-style PascalCase spelling of that design so
7// the eventual C# port lines up name-for-name. See docs/csharp-sdk-api.md.
8//
9// Entry point: SzEnvironment::GetLogging().
10//
11// ALL STATE IS NATIVE
12// Registrations, levels, formats and the default output live in native
13// libSzLogging. The SDK keeps one opaque handle per registration (plus the
14// std::function native calls) and nothing else: every registration is its own
15// native registration, and destroying its SzLogRegistration calls
16// SzLogging_unregisterCallback. There is no SDK registry, dispatcher, cache
17// or formatter.
18//
19// SENZING VERSIONS
20// Binds the libSzLogging API first released in Senzing 4.5.0 (the minimum).
21// Functionality that needs a newer native release (Senzing >= 4.5.1 / 4.6.0)
22// has its final signature here but throws SzConfigurationException naming the
23// native function and "Senzing >= 4.5.1/4.6.0" (or returns std::nullopt for
24// the SzLogRecord fields): per-callback levels (SzLogRegistration::SetLevel /
25// Level), the default-state getters (GetDefaultOutput / GetDefaultFormat /
26// GetDefaultLogLevel), append mode (SzLogOutput::AppendFile), thread-local
27// registrations (RegisterThreadLocalCallback, CaptureThreadLogs; 4.5.0 never
28// delivers to them, GDEV-4960), status-code error reporting, the record's
29// timestamp and thread ID, and changing sinks from inside a callback. Each
30// stub is marked SZ-FUTURE in src/core/SzCoreLogging.cpp. There is no runtime
31// version detection. On 4.5.0, SzLogRecord::ThreadHash() is the per-thread
32// handle (it is in every record's module).
33//
34// THE SENZING 4.5.0 USAGE RULE (documented, not enforced)
35// Change registrations, the default callback, the default output or the
36// default format ONLY while no engine threads are running: before the first
37// engine initialization (the first GetEngine()/GetDiagnostic(), which run
38// Sz_init) or after SzEnvironment::Destroy(). SetDefaultLogLevel and
39// GetEffectiveLogLevel are safe at any time. Joining your own worker threads
40// is not enough: engine initialization starts Senzing's lock-watcher thread,
41// which logs on its own until Destroy(). Why: in 4.5.0 these calls rebuild
42// native's sink list without synchronizing with threads that are logging. The
43// full concurrency guarantees need the GDEV-4960 native fix.
44//
45// VerboseLogging AND ENGINE INITIALIZATION
46// Each component initialization (Sz_init and the other *_init calls)
47// re-applies the environment's VerboseLogging to the default output (level
48// TRACE or ERROR, format Legacy) UNLESS the application configured logging
49// first. SetDefaultLogLevel, SetDefaultFormat and SetDefaultCallback count as
50// configuration (native keeps their settings from then on); SetDefaultOutput
51// and RegisterCallback do not. Registered callbacks keep their own level and
52// format either way.
53//
54// FLUSHING THE DEFAULT FILE OUTPUT
55// A file default output is flushed when the output is replaced (any
56// SetDefaultOutput call) or at process exit. On Senzing 4.5.0 Destroy() does
57// NOT flush it, so call SetDefaultOutput(...) after Destroy() before reading
58// the file.
59//
60// CALLBACK RULES
61// - Callbacks run synchronously on the thread that logs, concurrently across
62// threads. Keep them fast; hand expensive work to another thread.
63// - Do not call engine, config, config-manager, product or diagnostic methods
64// from a callback: some messages are logged while the engine holds internal
65// locks, so re-entering it can deadlock.
66// - Inside a callback, registering, setting a default callback and changing
67// the default output or format throw SzConfigurationException on 4.5.0
68// (native would rebuild the sink list it is iterating). SetDefaultLogLevel
69// and GetEffectiveLogLevel are allowed.
70// - An exception thrown by a callback is caught at the native boundary and
71// discarded; it never propagates into native code.
72//
73// CALLBACK LIFETIME
74// - Destroying a registration OUTSIDE any callback unregisters it and then
75// destroys the std::function (and everything it captured) before the
76// destructor returns. On 4.5.0 the usage rule guarantees no invocation is
77// in flight -- provided the registration is destroyed before the first
78// engine initialization or after Destroy().
79// - Mind the scope-exit order: locals are destroyed in reverse order of
80// declaration, so a registration declared AFTER the environment is
81// destroyed FIRST, while the engine is still initialized and may be logging
82// on its own threads (on 4.5.0: a use-after-free). Declare the registration
83// variable BEFORE the environment (assign it after GetLogging()), or call
84// SzEnvironment::Destroy() explicitly before the registration goes out of
85// scope:
86//
87// std::unique_ptr<senzing::sdk::SzLogRegistration> registration;
88// auto env = SzCoreEnvironment::NewBuilder()...Build();
89// registration = env->GetLogging().RegisterCallback(...);
90// // scope exit: env is destroyed (Destroy()) before registration
91//
92// - Destroying a registration INSIDE a callback (its own or another's)
93// deactivates it at once, so it is not called again, but leaves the native
94// registration in place and LEAKS the std::function: on 4.5.0 unregistering
95// there would rebuild the sink list native is iterating. The leaked native
96// registration stays in native's sink list for the REST OF THE PROCESS: it
97// keeps the effective level (GetEffectiveLogLevel) lowered to its minimum
98// level, and native keeps formatting every message at or above that level
99// for it (the SDK then drops them), a lasting cost at TRACE/DEBUG. Once the
100// native release hook ships, native frees it after its last invocation
101// instead.
102// - "Inside a callback" means inside a callback registered through THIS SDK.
103// - A default callback (SetDefaultCallback) is LEAKED when it is replaced:
104// 4.5.0 has no release hook, and freeing it would require the SDK to track
105// which callback is the current default. Set it once.
106// - Captured objects must not throw from their destructors (a throwing
107// destructor terminates the process, as everywhere in C++).
108#ifndef SENZING_SDK_SZLOGGING_HPP
109#define SENZING_SDK_SZLOGGING_HPP
110
111#include <algorithm>
112#include <array>
113#include <chrono>
114#include <cstdint>
115#include <filesystem>
116#include <functional>
117#include <memory>
118#include <mutex>
119#include <optional>
120#include <ostream>
121#include <string>
122#include <string_view>
123#include <utility>
124#include <vector>
125
127
128namespace senzing::sdk {
129
130// ============================================================================
131// SzLogLevel
132// ============================================================================
133
141enum class SzLogLevel : int32_t {
142 Trace = 0,
143 Debug = 1,
144 Info = 2,
145 Warn = 3,
146 Error = 4,
150 Off = 6
151};
152
157
158// ============================================================================
159// SzLogFormat
160// ============================================================================
161
163enum class SzLogFormat : int32_t {
168 Jsonl = 1,
170 Bare = 2,
175};
176
178inline constexpr std::array<SzLogFormat, 4> SzLogFormats{
181
182// ============================================================================
183// Names and parsing
184// ============================================================================
185
188[[nodiscard]] constexpr std::string_view ToString(SzLogLevel level) noexcept {
189 switch (level) {
191 return "TRACE";
193 return "DEBUG";
194 case SzLogLevel::Info:
195 return "INFO";
196 case SzLogLevel::Warn:
197 return "WARN";
199 return "ERROR";
201 return "CRITICAL";
202 case SzLogLevel::Off:
203 return "OFF";
204 }
205 return "UNKNOWN";
206}
207
210[[nodiscard]] constexpr std::string_view ToString(SzLogFormat format) noexcept {
211 switch (format) {
213 return "LEGACY";
215 return "JSONL";
217 return "BARE";
219 return "DEFAULT";
220 }
221 return "UNKNOWN";
222}
223
225inline std::ostream& operator<<(std::ostream& os, SzLogLevel level) {
226 return os << ToString(level);
227}
228
230inline std::ostream& operator<<(std::ostream& os, SzLogFormat format) {
231 return os << ToString(format);
232}
233
234namespace detail {
235
237inline std::string NormalizeLogName(std::string_view text) {
238 constexpr std::string_view kSpace = " \t\n\r\f\v";
239 const auto first = text.find_first_not_of(kSpace);
240 if (first == std::string_view::npos) {
241 return {};
242 }
243 const auto last = text.find_last_not_of(kSpace);
244 std::string out{text.substr(first, last - first + 1)};
245 std::transform(out.begin(), out.end(), out.begin(), [](char c) {
246 return (c >= 'a' && c <= 'z') ? static_cast<char>(c - 'a' + 'A') : c;
247 });
248 return out;
249}
250
251} // namespace detail
252
256[[nodiscard]] inline SzLogLevel ParseSzLogLevel(std::string_view text) {
257 const std::string name = detail::NormalizeLogName(text);
258 if (name == "WARNING") {
259 return SzLogLevel::Warn;
260 }
261 const auto* match = std::find_if(
262 SzLogLevels.begin(), SzLogLevels.end(),
263 [&name](SzLogLevel level) { return name == ToString(level); });
264 if (match != SzLogLevels.end()) {
265 return *match;
266 }
267 throw SzBadInputException("unknown log level \"" + std::string{text} +
268 "\"");
269}
270
274[[nodiscard]] inline SzLogFormat ParseSzLogFormat(std::string_view text) {
275 const std::string name = detail::NormalizeLogName(text);
276 if (name == "JSON") {
277 return SzLogFormat::Jsonl;
278 }
279 const auto* match = std::find_if(
280 SzLogFormats.begin(), SzLogFormats.end(),
281 [&name](SzLogFormat format) { return name == ToString(format); });
282 if (match != SzLogFormats.end()) {
283 return *match;
284 }
285 throw SzBadInputException("unknown log format \"" + std::string{text} +
286 "\"");
287}
288
289// ============================================================================
290// SzLogOutput
291// ============================================================================
292
294enum class SzLogOutputType : int32_t {
295 Stderr = 0,
296 Stdout = 1,
297 File = 2,
298 Null = 3,
302};
303
307public:
309 SzLogOutput() = default;
310
312 [[nodiscard]] static SzLogOutput Stderr() { return {}; }
313
315 [[nodiscard]] static SzLogOutput Stdout() {
316 return SzLogOutput{SzLogOutputType::Stdout, {}, false};
317 }
318
320 [[nodiscard]] static SzLogOutput Null() {
321 return SzLogOutput{SzLogOutputType::Null, {}, false};
322 }
323
325 [[nodiscard]] static SzLogOutput Callback() {
326 return SzLogOutput{SzLogOutputType::Callback, {}, false};
327 }
328
331 [[nodiscard]] static SzLogOutput File(std::filesystem::path filePath) {
332 return SzLogOutput{SzLogOutputType::File, std::move(filePath), false};
333 }
334
337 [[nodiscard]] static SzLogOutput AppendFile(
338 std::filesystem::path filePath) {
339 return SzLogOutput{SzLogOutputType::File, std::move(filePath), true};
340 }
341
343 [[nodiscard]] SzLogOutputType OutputType() const noexcept { return type_; }
344
346 [[nodiscard]] const std::filesystem::path& Path() const noexcept {
347 return path_;
348 }
349
351 [[nodiscard]] bool IsAppend() const noexcept { return append_; }
352
353 bool operator==(const SzLogOutput& other) const = default;
354
355private:
356 SzLogOutput(SzLogOutputType outputType, std::filesystem::path filePath,
357 bool appendMode)
358 : type_(outputType), path_(std::move(filePath)), append_(appendMode) {}
359
361 std::filesystem::path path_;
362 bool append_{false};
363};
364
365// ============================================================================
366// SzLogCallbackOptions
367// ============================================================================
368
378public:
380 // cppcheck-suppress noExplicitConstructor ; implicit by design (see above)
381 constexpr SzLogCallbackOptions(SzLogLevel minLevel) noexcept // NOLINT
382 : minLevel_(minLevel) {}
383
386 SzLogFormat format) noexcept
387 : minLevel_(minLevel), format_(format) {}
388
390 [[nodiscard]] constexpr SzLogCallbackOptions WithFormat(
391 SzLogFormat format) const noexcept {
392 return SzLogCallbackOptions{minLevel_, format};
393 }
394
396 [[nodiscard]] constexpr SzLogLevel MinLevel() const noexcept {
397 return minLevel_;
398 }
399
401 [[nodiscard]] constexpr SzLogFormat Format() const noexcept {
402 return format_;
403 }
404
405 constexpr bool operator==(const SzLogCallbackOptions& other) const =
406 default;
407
408private:
409 SzLogLevel minLevel_;
411};
412
413// ============================================================================
414// SzLogRecord / SzLogEntry
415// ============================================================================
416
422 std::string Module;
424 std::optional<std::string> ThreadHash;
426 std::string Message;
429 std::optional<std::chrono::system_clock::time_point> Timestamp;
432 std::optional<uint64_t> ThreadID;
433
434 bool operator==(const SzLogEntry& other) const = default;
435};
436
438inline std::ostream& operator<<(std::ostream& os, const SzLogEntry& entry) {
439 return os << entry.Message;
440}
441
452public:
455 constexpr SzLogRecord(
456 SzLogLevel level, std::string_view rawModule, std::string_view message,
457 std::optional<int64_t> timestampNs = std::nullopt,
458 std::optional<uint64_t> threadID = std::nullopt) noexcept
459 : level_(level),
460 rawModule_(rawModule),
461 message_(message),
462 timestampNs_(timestampNs),
463 threadID_(threadID) {}
464
466 [[nodiscard]] constexpr SzLogLevel Level() const noexcept { return level_; }
467
470 [[nodiscard]] constexpr std::string_view Module() const noexcept {
471 const auto colon = rawModule_.rfind(':');
472 return colon == std::string_view::npos ? rawModule_
473 : rawModule_.substr(0, colon);
474 }
475
479 [[nodiscard]] constexpr std::optional<std::string_view> ThreadHash()
480 const noexcept {
481 const auto colon = rawModule_.rfind(':');
482 if (colon == std::string_view::npos) {
483 return std::nullopt;
484 }
485 return rawModule_.substr(colon + 1);
486 }
487
489 [[nodiscard]] constexpr std::string_view Message() const noexcept {
490 return message_;
491 }
492
494 [[nodiscard]] constexpr std::string_view RawModule() const noexcept {
495 return rawModule_;
496 }
497
500 [[nodiscard]] constexpr std::optional<int64_t> TimestampNs()
501 const noexcept {
502 return timestampNs_;
503 }
504
507 [[nodiscard]] std::optional<std::chrono::system_clock::time_point>
508 Timestamp() const {
509 if (!timestampNs_) {
510 return std::nullopt;
511 }
512 return std::chrono::system_clock::time_point{
513 std::chrono::duration_cast<std::chrono::system_clock::duration>(
514 std::chrono::nanoseconds{*timestampNs_})};
515 }
516
519 [[nodiscard]] constexpr std::optional<uint64_t> ThreadID() const noexcept {
520 return threadID_;
521 }
522
524 [[nodiscard]] SzLogEntry ToEntry() const {
525 SzLogEntry entry;
526 entry.Level = level_;
527 entry.Module = std::string{Module()};
528 if (const auto hash = ThreadHash()) {
529 entry.ThreadHash = std::string{*hash};
530 }
531 entry.Message = std::string{message_};
532 entry.Timestamp = Timestamp();
533 entry.ThreadID = threadID_;
534 return entry;
535 }
536
537private:
538 SzLogLevel level_;
539 std::string_view rawModule_;
540 std::string_view message_;
541 std::optional<int64_t> timestampNs_;
542 std::optional<uint64_t> threadID_;
543};
544
546inline std::ostream& operator<<(std::ostream& os, const SzLogRecord& record) {
547 return os << record.Message();
548}
549
553using SzLogCallback = std::function<void(const SzLogRecord&)>;
554
555// ============================================================================
556// SzLogRegistration
557// ============================================================================
558
573public:
575 virtual ~SzLogRegistration() = default;
576
581
587 virtual void SetLevel(SzLogLevel minLevel) = 0;
588
591 [[nodiscard]] virtual SzLogLevel Level() = 0;
592
594 virtual void Unregister() = 0;
595
599 virtual void Leak() = 0;
600
601protected:
602 SzLogRegistration() = default;
603};
604
605// ============================================================================
606// SzLogCapture
607// ============================================================================
608
615public:
617 struct Buffer {
618 std::mutex Mutex;
619 std::vector<SzLogEntry> Entries;
620 };
621
622 SzLogCapture(std::unique_ptr<SzLogRegistration> registration,
623 std::shared_ptr<Buffer> buffer) noexcept
624 : registration_(std::move(registration)), buffer_(std::move(buffer)) {}
625
628 [[nodiscard]] std::vector<SzLogEntry> Finish() {
629 registration_.reset();
630 if (!buffer_) {
631 return {};
632 }
633 std::lock_guard<std::mutex> guard(buffer_->Mutex);
634 return std::exchange(buffer_->Entries, {});
635 }
636
637private:
638 std::unique_ptr<SzLogRegistration> registration_;
639 std::shared_ptr<Buffer> buffer_;
640};
641
642// ============================================================================
643// SzLogging
644// ============================================================================
645
658public:
659 virtual ~SzLogging() = default;
660
670 [[nodiscard]] virtual std::unique_ptr<SzLogRegistration> RegisterCallback(
671 const SzLogCallbackOptions& options, SzLogCallback callback) = 0;
672
680 [[nodiscard]] virtual std::unique_ptr<SzLogRegistration>
682 SzLogCallback callback) = 0;
683
695 virtual void SetDefaultCallback(const SzLogCallbackOptions& options,
696 SzLogCallback callback) = 0;
697
715 virtual void SetDefaultOutput(const SzLogOutput& output) = 0;
716
719 [[nodiscard]] virtual SzLogOutput GetDefaultOutput() = 0;
720
727 virtual void SetDefaultFormat(SzLogFormat format) = 0;
728
731 [[nodiscard]] virtual SzLogFormat GetDefaultFormat() = 0;
732
738 virtual void SetDefaultLogLevel(SzLogLevel level) = 0;
739
743 [[nodiscard]] virtual SzLogLevel GetDefaultLogLevel() = 0;
744
753 [[nodiscard]] virtual SzLogLevel GetEffectiveLogLevel() = 0;
754
762 const SzLogCallbackOptions& options) {
763 auto buffer = std::make_shared<SzLogCapture::Buffer>();
764 auto registration = RegisterThreadLocalCallback(
765 options, [sink = buffer](const SzLogRecord& record) {
766 std::lock_guard<std::mutex> guard(sink->Mutex);
767 sink->Entries.push_back(record.ToEntry());
768 });
769 return SzLogCapture{std::move(registration), std::move(buffer)};
770 }
771};
772
773} // namespace senzing::sdk
774
775#endif // SENZING_SDK_SZLOGGING_HPP
Registration parameters: the callback's minimum level and the format native applies to SzLogRecord::M...
Definition SzLogging.hpp:377
constexpr SzLogFormat Format() const noexcept
Format native applies to the message.
Definition SzLogging.hpp:401
constexpr SzLogCallbackOptions WithFormat(SzLogFormat format) const noexcept
Returns a copy of these options with format instead.
Definition SzLogging.hpp:390
constexpr SzLogCallbackOptions(SzLogLevel minLevel) noexcept
Options with minLevel and the Bare format.
Definition SzLogging.hpp:381
constexpr SzLogCallbackOptions(SzLogLevel minLevel, SzLogFormat format) noexcept
Options with minLevel and format.
Definition SzLogging.hpp:385
constexpr bool operator==(const SzLogCallbackOptions &other) const =default
constexpr SzLogLevel MinLevel() const noexcept
Minimum level delivered to the callback.
Definition SzLogging.hpp:396
Collects the records logged on the thread that created it until Finish().
Definition SzLogging.hpp:614
SzLogCapture(std::unique_ptr< SzLogRegistration > registration, std::shared_ptr< Buffer > buffer) noexcept
Definition SzLogging.hpp:622
std::vector< SzLogEntry > Finish()
Unregisters, then returns everything captured.
Definition SzLogging.hpp:628
Destination of native's default output.
Definition SzLogging.hpp:306
static SzLogOutput Null()
Discard; only registered callbacks receive messages.
Definition SzLogging.hpp:320
bool IsAppend() const noexcept
True for a file output that keeps existing content.
Definition SzLogging.hpp:351
static SzLogOutput Stderr()
Standard error (the native default).
Definition SzLogging.hpp:312
static SzLogOutput AppendFile(std::filesystem::path filePath)
A file output that appends to the file, keeping what is already there (SZ_LOG_OUTPUT_FILE_APPEND).
Definition SzLogging.hpp:337
static SzLogOutput Callback()
A default callback (get-only: SetDefaultOutput rejects it).
Definition SzLogging.hpp:325
bool operator==(const SzLogOutput &other) const =default
SzLogOutputType OutputType() const noexcept
The kind of destination.
Definition SzLogging.hpp:343
static SzLogOutput Stdout()
Standard output.
Definition SzLogging.hpp:315
SzLogOutput()=default
Standard error (the native default).
const std::filesystem::path & Path() const noexcept
The file path (empty unless OutputType() is File).
Definition SzLogging.hpp:346
static SzLogOutput File(std::filesystem::path filePath)
A file output that truncates the file when it is opened (SZ_LOG_OUTPUT_FILE).
Definition SzLogging.hpp:331
One log message, borrowed from native for the duration of a callback.
Definition SzLogging.hpp:451
constexpr SzLogRecord(SzLogLevel level, std::string_view rawModule, std::string_view message, std::optional< int64_t > timestampNs=std::nullopt, std::optional< uint64_t > threadID=std::nullopt) noexcept
Builds a record over native's fields.
Definition SzLogging.hpp:455
constexpr std::optional< uint64_t > ThreadID() const noexcept
OS id of the thread that logged the message.
Definition SzLogging.hpp:519
constexpr std::optional< std::string_view > ThreadHash() const noexcept
The thread hash after the last ':' of native's module ("82eb15f5faba9bab"), if present.
Definition SzLogging.hpp:479
constexpr std::string_view Message() const noexcept
The message exactly as native formatted it for this registration.
Definition SzLogging.hpp:489
constexpr SzLogLevel Level() const noexcept
The message's severity.
Definition SzLogging.hpp:466
SzLogEntry ToEntry() const
An owned copy, for queues and buffers.
Definition SzLogging.hpp:524
constexpr std::optional< int64_t > TimestampNs() const noexcept
When native logged the message: UTC nanoseconds since the Unix epoch.
Definition SzLogging.hpp:500
constexpr std::string_view RawModule() const noexcept
Native's module string, unparsed ("szstatic:82eb15f5faba9bab").
Definition SzLogging.hpp:494
constexpr std::string_view Module() const noexcept
The module name: native's module up to its last ':' (for "szstatic:82eb15f5faba9bab",...
Definition SzLogging.hpp:470
std::optional< std::chrono::system_clock::time_point > Timestamp() const
When native logged the message (UTC), at the platform's system_clock precision.
Definition SzLogging.hpp:508
virtual void SetLevel(SzLogLevel minLevel)=0
Changes this callback's minimum level in place (SzLogging_setCallbackLevel).
SzLogRegistration & operator=(const SzLogRegistration &)=delete
virtual void Unregister()=0
Unregisters now (same as destroying the registration). Idempotent.
virtual SzLogLevel Level()=0
This callback's current minimum level (SzLogging_getCallbackLevel).
virtual void Leak()=0
Keeps the callback registered (and called) for the rest of the process; the destructor then does noth...
virtual ~SzLogRegistration()=default
Unregisters the callback unless Unregister() or Leak() already ran.
SzLogRegistration(const SzLogRegistration &)=delete
SzLogRegistration & operator=(SzLogRegistration &&)=delete
SzLogRegistration(SzLogRegistration &&)=delete
Senzing native logging (libSzLogging).
Definition SzLogging.hpp:657
SzLogCapture CaptureThreadLogs(const SzLogCallbackOptions &options)
Captures the records logged on the calling thread until SzLogCapture::Finish(): one thread-local regi...
Definition SzLogging.hpp:761
virtual void SetDefaultFormat(SzLogFormat format)=0
Sets the default output's format (SzLogging_setDefaultFormatter).
virtual ~SzLogging()=default
virtual SzLogLevel GetEffectiveLogLevel()=0
The effective level (SzLogging_getLogLevel): the minimum over the default output and every registered...
virtual void SetDefaultLogLevel(SzLogLevel level)=0
Sets the default output's level (SzLogging_setLogLevel).
virtual std::unique_ptr< SzLogRegistration > RegisterCallback(const SzLogCallbackOptions &options, SzLogCallback callback)=0
Registers callback for messages from every thread (SzLogging_registerCallbackWithFormat).
virtual SzLogFormat GetDefaultFormat()=0
The default output's format (SzLogging_getDefaultFormatter).
virtual void SetDefaultOutput(const SzLogOutput &output)=0
Sets the default output (SzLogging_setDefaultOutput).
virtual std::unique_ptr< SzLogRegistration > RegisterThreadLocalCallback(const SzLogCallbackOptions &options, SzLogCallback callback)=0
Registers callback for messages logged on the CALLING OS THREAD only.
virtual SzLogLevel GetDefaultLogLevel()=0
The default output's level, exactly what SetDefaultLogLevel set (SzLogging_getDefaultLogLevel).
virtual void SetDefaultCallback(const SzLogCallbackOptions &options, SzLogCallback callback)=0
Makes callback the default output, at options.MinLevel() and in options.Format() (SzLogging_setDefaul...
virtual SzLogOutput GetDefaultOutput()=0
The current default output (SzLogging_getDefaultOutput).
Definition SzLogging.hpp:234
std::string NormalizeLogName(std::string_view text)
Upper-cases ASCII letters and strips surrounding whitespace.
Definition SzLogging.hpp:237
Definition SzCoreConfig.hpp:20
std::function< void(const SzLogRecord &)> SzLogCallback
A log callback.
Definition SzLogging.hpp:553
constexpr std::array< SzLogFormat, 4 > SzLogFormats
All formats.
Definition SzLogging.hpp:178
SzLogOutputType
The kind of destination of native's default output (SZ_LOG_OUTPUT_*).
Definition SzLogging.hpp:294
@ File
A file opened by native (truncate or append).
Definition SzLogging.hpp:297
@ Stdout
Standard output.
Definition SzLogging.hpp:296
@ Callback
A default callback is set.
Definition SzLogging.hpp:301
@ Stderr
Standard error (the native default).
Definition SzLogging.hpp:295
@ Null
Discard; only registered callbacks receive messages.
Definition SzLogging.hpp:298
SzLogLevel
Log severity.
Definition SzLogging.hpp:141
@ Critical
Critical errors (SZ_LOG_LEVEL_CRITICAL).
Definition SzLogging.hpp:147
@ Info
Informational messages (SZ_LOG_LEVEL_INFO).
Definition SzLogging.hpp:144
@ Warn
Warnings (SZ_LOG_LEVEL_WARN).
Definition SzLogging.hpp:145
@ Error
Errors (SZ_LOG_LEVEL_ERROR).
Definition SzLogging.hpp:146
@ Debug
Debug information (SZ_LOG_LEVEL_DEBUG).
Definition SzLogging.hpp:143
@ Off
Nothing is delivered (SZ_LOG_LEVEL_OFF).
Definition SzLogging.hpp:150
@ Trace
Most verbose: execution flow (SZ_LOG_LEVEL_TRACE).
Definition SzLogging.hpp:142
constexpr std::array< SzLogLevel, 7 > SzLogLevels
All levels, most verbose first.
Definition SzLogging.hpp:154
SzLogFormat ParseSzLogFormat(std::string_view text)
Parses a format name.
Definition SzLogging.hpp:274
SzLogFormat
Message format, applied by native (SZ_LOG_FORMAT_*).
Definition SzLogging.hpp:163
@ Legacy
YYYY-MM-DD HH:MM:SS.mmm [module:hash] SEV: msg, in local time.
Definition SzLogging.hpp:165
@ Bare
The message text only.
Definition SzLogging.hpp:170
@ Jsonl
One JSON object per line: timestamp, module, severity, message.
Definition SzLogging.hpp:168
@ Default
For the default output: spdlog's default pattern [YYYY-MM-DD HH:MM:SS.mmm] [module] [level] msg (loca...
Definition SzLogging.hpp:174
constexpr std::string_view ToString(SzLogLevel level) noexcept
The canonical upper-case name: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "CRITICAL" or "OFF" ("UNKNO...
Definition SzLogging.hpp:188
SzLogLevel ParseSzLogLevel(std::string_view text)
Parses a level name.
Definition SzLogging.hpp:256
std::ostream & operator<<(std::ostream &os, SzLogLevel level)
Writes ToString(level).
Definition SzLogging.hpp:225
The buffer shared between the capture and its callback.
Definition SzLogging.hpp:617
std::mutex Mutex
Definition SzLogging.hpp:618
std::vector< SzLogEntry > Entries
Definition SzLogging.hpp:619
An owned copy of an SzLogRecord, for queues and buffers.
Definition SzLogging.hpp:418
std::string Module
The module name (SzLogRecord::Module()).
Definition SzLogging.hpp:422
std::optional< std::string > ThreadHash
The thread hash (SzLogRecord::ThreadHash()).
Definition SzLogging.hpp:424
std::string Message
The message as native formatted it.
Definition SzLogging.hpp:426
SzLogLevel Level
The message's severity.
Definition SzLogging.hpp:420
bool operator==(const SzLogEntry &other) const =default
std::optional< std::chrono::system_clock::time_point > Timestamp
When native logged the message (UTC); std::nullopt until Senzing >= 4.5.1 / 4.6.0.
Definition SzLogging.hpp:429
std::optional< uint64_t > ThreadID
OS id of the logging thread; std::nullopt until Senzing >= 4.5.1 / 4.6.0.
Definition SzLogging.hpp:432