logging.go
logging.go - Overview
-
Overview This file defines a
logging
struct that implements thesqlstore.SQLStoreHook
interface to log SQL queries executed viabun
. It provides a factory for creatinglogging
instances. -
Detailed Documentation
struct logging
- Purpose: Implements the
bun.QueryHook
interface to log SQL queries. - Fields:
QueryHook
: An embeddedbun.QueryHook
interface.logger
: A pointer to aslog.Logger
instance for logging messages.level
: Aslog.Level
representing the logging level.
func NewLoggingFactory
- Purpose: Returns a factory for creating
logging
instances. - Returns: A
factory.ProviderFactory[sqlstore.SQLStoreHook, sqlstore.Config]
that createslogging
instances.
func NewLogging
- Purpose: Creates a new
logging
instance. - Parameters:
ctx
(context.Context): The context for the operation.providerSettings
(factory.ProviderSettings): Settings for the provider.config
(sqlstore.Config): Configuration for the SQL store.
- Returns:
sqlstore.SQLStoreHook
: A newlogging
instance.error
: An error if the instance cannot be created.
func (logging) BeforeQuery
- Purpose: A no-op function that implements the
BeforeQuery
method of thebun.QueryHook
interface. - Parameters:
ctx
(context.Context): The context for the operation.event
(*bun.QueryEvent): The query event.
- Returns:
context.Context
: The context.
func (hook logging) AfterQuery
- Purpose: Logs SQL queries after they are executed. Implements the
AfterQuery
method of thebun.QueryHook
interface. - Parameters:
ctx
(context.Context): The context for the operation.event
(*bun.QueryEvent): The query event containing information about the query.
- Returns: None
-
Code Examples None
-
Clarity and Accuracy The documentation reflects the code accurately.
-
Markdown & MDX Perfection The markdown is properly formatted.
-
Edge Cases To Avoid Breaking MDX No issues.
-
Getting Started Relevance Include in Getting Started: YES