Lightweight 0.20250904.0
Loading...
Searching...
No Matches
Lightweight::SqlLogger Class Referenceabstract

Represents a logger for SQL operations. More...

#include <SqlLogger.hpp>

Inherited by Lightweight::SqlLogger::Null.

Public Types

enum class  SupportBindLogging : uint8_t { No , Yes }
 Mandates the support for logging bind operations. More...
 
using MessageWriter = std::function< void(std::string)>
 Type definition for a function that writes messages.
 

Public Member Functions

LIGHTWEIGHT_API SqlLogger (SqlLogger const &)=default
 
LIGHTWEIGHT_API SqlLogger (SqlLogger &&)=default
 
LIGHTWEIGHT_API SqlLoggeroperator= (SqlLogger const &)=default
 
LIGHTWEIGHT_API SqlLoggeroperator= (SqlLogger &&)=default
 
LIGHTWEIGHT_API SqlLogger (SupportBindLogging supportBindLogging, MessageWriter writer={})
 
LIGHTWEIGHT_API void SetLoggingSink (MessageWriter writer={})
 
virtual void OnWarning (std::string_view const &message)=0
 Invoked on a warning.
 
virtual void OnError (SqlError errorCode, std::source_location sourceLocation=std::source_location::current())=0
 Invoked on ODBC SQL error occurred.
 
virtual void OnError (SqlErrorInfo const &errorInfo, std::source_location sourceLocation=std::source_location::current())=0
 Invoked an ODBC SQL error occurred, with extended error information.
 
virtual void OnScopedTimerStart (std::string const &tag)=0
 Invoked when a scoped code region needs to be timed and logged. The region starts with this call.
 
virtual void OnScopedTimerStop (std::string const &tag)=0
 Invoked when a scoped code region needs to be timed and logged. The region ends with this call.
 
virtual void OnConnectionOpened (SqlConnection const &connection)=0
 Invoked when a connection is opened.
 
virtual void OnConnectionClosed (SqlConnection const &connection)=0
 Invoked when a connection is closed.
 
virtual void OnConnectionIdle (SqlConnection const &connection)=0
 Invoked when a connection is idle.
 
virtual void OnConnectionReuse (SqlConnection const &connection)=0
 Invoked when a connection is reused.
 
virtual void OnExecuteDirect (std::string_view const &query)=0
 Invoked when a direct query is executed.
 
virtual void OnPrepare (std::string_view const &query)=0
 Invoked when a query is prepared.
 
template<typename T >
void OnBindInputParameter (std::string_view const &name, T &&value)
 Invoked when an input parameter is bound.
 
virtual void OnBind (std::string_view const &name, std::string value)=0
 Invoked when an input parameter is bound, by name.
 
virtual void OnExecute (std::string_view const &query)=0
 Invoked when a prepared query is executed.
 
virtual void OnExecuteBatch ()=0
 Invoked when a batch of queries is executed.
 
virtual void OnFetchRow ()=0
 Invoked when a row is fetched.
 
virtual void OnFetchEnd ()=0
 Invoked when fetching is done.
 

Static Public Member Functions

static LIGHTWEIGHT_API Null & NullLogger () noexcept
 Retrieves a null logger that does nothing.
 
static LIGHTWEIGHT_API SqlLoggerStandardLogger ()
 Retrieves a logger that logs to standard output.
 
static LIGHTWEIGHT_API SqlLoggerTraceLogger ()
 Retrieves a logger that logs to the trace logger.
 
static LIGHTWEIGHT_API SqlLoggerGetLogger ()
 Retrieves the currently configured logger.
 
static LIGHTWEIGHT_API void SetLogger (SqlLogger &logger)
 

Protected Attributes

MessageWriter _messageWriter
 

Detailed Description

Represents a logger for SQL operations.

Definition at line 21 of file SqlLogger.hpp.

Member Typedef Documentation

◆ MessageWriter

using Lightweight::SqlLogger::MessageWriter = std::function<void(std::string )>

Type definition for a function that writes messages.

Definition at line 39 of file SqlLogger.hpp.

Member Enumeration Documentation

◆ SupportBindLogging

enum class Lightweight::SqlLogger::SupportBindLogging : uint8_t
strong

Mandates the support for logging bind operations.

Definition at line 25 of file SqlLogger.hpp.

Constructor & Destructor Documentation

◆ SqlLogger()

LIGHTWEIGHT_API Lightweight::SqlLogger::SqlLogger ( SupportBindLogging  supportBindLogging,
MessageWriter  writer = {} 
)
explicit

Constructs a new logger.

Parameters
supportBindLoggingIndicates if the logger should support bind logging.

Member Function Documentation

◆ SetLoggingSink()

LIGHTWEIGHT_API void Lightweight::SqlLogger::SetLoggingSink ( MessageWriter  writer = {})

Sets the logging sink for the logger.

Parameters
writerA function that takes a message string and writes it to the desired output.

◆ OnBindInputParameter()

template<typename T >
void Lightweight::SqlLogger::OnBindInputParameter ( std::string_view const &  name,
T &&  value 
)
inline

Invoked when an input parameter is bound.

Definition at line 87 of file SqlLogger.hpp.

References OnBind().

Referenced by Lightweight::SqlStatement::Execute().

◆ SetLogger()

static LIGHTWEIGHT_API void Lightweight::SqlLogger::SetLogger ( SqlLogger logger)
static

Member Data Documentation

◆ _messageWriter

MessageWriter Lightweight::SqlLogger::_messageWriter
protected

Definition at line 134 of file SqlLogger.hpp.


The documentation for this class was generated from the following file: