|
Lightweight 0.20250904.0
|
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 SqlLogger & | operator= (SqlLogger const &)=default |
| LIGHTWEIGHT_API SqlLogger & | operator= (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 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 |
Represents a logger for SQL operations.
Definition at line 21 of file SqlLogger.hpp.
| 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.
|
strong |
Mandates the support for logging bind operations.
Definition at line 25 of file SqlLogger.hpp.
|
explicit |
Constructs a new logger.
| supportBindLogging | Indicates if the logger should support bind logging. |
| LIGHTWEIGHT_API void Lightweight::SqlLogger::SetLoggingSink | ( | MessageWriter | writer = {} | ) |
Sets the logging sink for the logger.
| writer | A function that takes a message string and writes it to the desired output. |
|
inline |
Invoked when an input parameter is bound.
Definition at line 87 of file SqlLogger.hpp.
References OnBind().
Referenced by Lightweight::SqlStatement::Execute().
|
static |
Sets the current logger.
The ownership of the logger is not transferred and remains with the caller.
References OnBind(), OnConnectionClosed(), OnConnectionIdle(), OnConnectionOpened(), OnConnectionReuse(), OnError(), OnExecute(), OnExecuteBatch(), OnExecuteDirect(), OnFetchEnd(), OnFetchRow(), OnPrepare(), OnScopedTimerStart(), OnScopedTimerStop(), and OnWarning().
|
protected |
Definition at line 134 of file SqlLogger.hpp.