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

#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
 Default copy constructor.
 
LIGHTWEIGHT_API SqlLogger (SqlLogger &&)=default
 Default move constructor.
 
LIGHTWEIGHT_API SqlLogger & operator= (SqlLogger const &)=default
 Default copy assignment operator.
 
LIGHTWEIGHT_API SqlLogger & operator= (SqlLogger &&)=default
 Default move assignment operator.
 
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 OnFetchBlock (std::size_t)
 Invoked once per block-prefetch round-trip (one SQLFetchScroll that materialized a whole row block on the transparent prefetch path), with the number of rows the block yielded.
 
virtual void OnFetchEnd ()=0
 Invoked when fetching is done.
 
virtual void OnStatementError (SqlErrorInfo const &errorInfo, std::string_view query, std::source_location sourceLocation)
 Invoked when an operation on a statement failed, naming that statement's own query.
 
virtual void OnExecuteNativeBatch (std::string_view query)
 Invoked when a prepared query is executed as one native row-wise batch.
 

Static Public Member Functions

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

Protected Attributes

MessageWriter _messageWriter
 The function used to write log messages.
 

Detailed Description

Represents a logger for SQL operations.

Definition at line 22 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 44 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 26 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.
writerOptional message writer function for log output.

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 93 of file SqlLogger.hpp.

References OnBind().

◆ OnFetchBlock()

virtual void Lightweight::SqlLogger::OnFetchBlock ( std::size_t  )
inlinevirtual

Invoked once per block-prefetch round-trip (one SQLFetchScroll that materialized a whole row block on the transparent prefetch path), with the number of rows the block yielded.

Non-pure with an empty default so existing loggers need no change; override to observe how many network round-trips a query actually cost (N rows at depth D collapse to ceil(N/D) blocks). The argument is the number of rows materialized by this block fetch (0 at end of result set).

Definition at line 123 of file SqlLogger.hpp.

◆ OnStatementError()

virtual void Lightweight::SqlLogger::OnStatementError ( SqlErrorInfo const &  errorInfo,
std::string_view  query,
std::source_location  sourceLocation 
)
inlinevirtual

Invoked when an operation on a statement failed, naming that statement's own query.

Non-pure so existing loggers need no change: the default forwards to OnError. Unlike a query remembered from OnPrepare or OnExecute, which may belong to any statement of the process, query is the one the failure belongs to.

Parameters
errorInfoThe diagnostics of the failure.
queryThe statement's prepared query; empty if it has none, as after a direct execution.
sourceLocationWhere the failure was reported from.

Definition at line 137 of file SqlLogger.hpp.

References OnError().

◆ OnExecuteNativeBatch()

virtual void Lightweight::SqlLogger::OnExecuteNativeBatch ( std::string_view  query)
inlinevirtual

Invoked when a prepared query is executed as one native row-wise batch.

Non-pure so existing loggers need no change: the default forwards to OnExecuteBatch.

Parameters
queryThe query being executed.

Definition at line 149 of file SqlLogger.hpp.

References OnExecuteBatch().

◆ SetLogger()

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

Sets the current logger.

The ownership of the logger is not transferred and remains with the caller. Statements and connections report to the current logger when they are destroyed, which for those owned by statics (such as the migration manager's) happens during static destruction. A logger installed here must therefore outlive them, or be replaced (e.g. by NullLogger) before it is destroyed. The built-in loggers are never destroyed.

Member Data Documentation

◆ _messageWriter

MessageWriter Lightweight::SqlLogger::_messageWriter
protected

The function used to write log messages.

Definition at line 179 of file SqlLogger.hpp.


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