DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
docwire::log Namespace Reference

Provides a modern, high-performance, and structured logging framework. More...

Classes

struct  stderr_redirect
 Tag for log entries that contain content redirected from stderr. More...
 
class  cerr_redirection
 
class  record
 
class  scope
 Represents a logging scope. More...
 
class  state_saver
 RAII class to save and restore logging state (sink and filter). More...
 
struct  audit
 Tag for high-level, production-worthy operational events. More...
 
struct  scope_enter
 Tag automatically added to a log entry when a log_scope is entered. More...
 
struct  scope_exit
 Tag automatically added to a log entry when a log_scope is exited. More...
 
struct  return_value
 Tag automatically added to a log entry created by log_return. More...
 

Functions

DOCWIRE_CORE_EXPORT void set_filter (const std::string &filter_spec)
 
DOCWIRE_CORE_EXPORT std::string get_filter ()
 Gets the current log filter specification string. More...
 
DOCWIRE_CORE_EXPORT void set_sink (std::function< void(const log::record &)> callback)
 Sets the global callback function that will receive all enabled log records. More...
 
DOCWIRE_CORE_EXPORT std::function< void(const record &)> get_sink ()
 Gets the current log sink function. More...
 
DOCWIRE_CORE_EXPORT serialization::object create_base_metadata (source_location location)
 Creates a base serialization object with common metadata. More...
 
template<typename... Args>
void entry (source_location location, std::tuple< Args... > &&args_tuple)
 
template<typename T , typename... Args>
T && and_forward_value (const char *expr_str, T &&value, source_location location, Args &&... args)
 
DOCWIRE_CORE_EXPORT std::function< void(const record &)> json_stream_sink (ref_or_owned< std::ostream > stream)
 
template<typename... Args>
 scope (const Args &...) -> scope< Args... >
 

Detailed Description

Provides a modern, high-performance, and structured logging framework.

The docwire::log namespace contains a powerful logging system designed for both deep debugging and zero-overhead production use. It features:

  • Structured JSON Output: All log records are generated as structured JSON objects, making them easy to parse, query, and integrate with modern log analysis platforms.
  • Zero-Cost in Release Builds: By default, most logging calls (log_entry, log_scope) are completely compiled out in release builds (NDEBUG is defined), ensuring they have zero performance impact on your production code. Only logs explicitly marked with a persistent tag (like log::audit) are retained.
  • Sink and Filter Model: The framework is silent by default. To receive logs, you must programmatically set a "sink" (a callback function that receives log records) and a "filter" (a string that specifies which logs to enable).
  • Powerful Filtering: Filter logs based on source file, function name, or custom tags using a simple wildcard-based syntax.

Function Documentation

◆ create_base_metadata()

DOCWIRE_CORE_EXPORT serialization::object docwire::log::create_base_metadata ( source_location  location)

Creates a base serialization object with common metadata.

Parameters
locationThe source location to be included in the metadata.
Returns
A serialization::object containing timestamp, file, line, function, and thread_id.

◆ get_filter()

DOCWIRE_CORE_EXPORT std::string docwire::log::get_filter ( )

Gets the current log filter specification string.

Returns
The current filter string.

◆ get_sink()

DOCWIRE_CORE_EXPORT std::function<void(const record&)> docwire::log::get_sink ( )

Gets the current log sink function.

Returns
The current sink function.

◆ set_sink()

DOCWIRE_CORE_EXPORT void docwire::log::set_sink ( std::function< void(const log::record &)>  callback)

Sets the global callback function that will receive all enabled log records.

Parameters
callbackA function that takes a const serialization::object& and processes it. This is the primary mechanism for customizing the log sink.
See also
json_stream_sink