Skip to main content

logging.go

logging.go - Overview

  1. Overview This file defines a logging struct that implements the sqlstore.SQLStoreHook interface to log SQL queries executed via bun. It provides a factory for creating logging instances.

  2. Detailed Documentation

struct logging

  • Purpose: Implements the bun.QueryHook interface to log SQL queries.
  • Fields:
    • QueryHook: An embedded bun.QueryHook interface.
    • logger: A pointer to a slog.Logger instance for logging messages.
    • level: A slog.Level representing the logging level.

func NewLoggingFactory

  • Purpose: Returns a factory for creating logging instances.
  • Returns: A factory.ProviderFactory[sqlstore.SQLStoreHook, sqlstore.Config] that creates logging 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 new logging instance.
    • error: An error if the instance cannot be created.

func (logging) BeforeQuery

  • Purpose: A no-op function that implements the BeforeQuery method of the bun.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 the bun.QueryHook interface.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • event (*bun.QueryEvent): The query event containing information about the query.
  • Returns: None
  1. Code Examples None

  2. Clarity and Accuracy The documentation reflects the code accurately.

  3. Markdown & MDX Perfection The markdown is properly formatted.

  4. Edge Cases To Avoid Breaking MDX No issues.

  5. Getting Started Relevance Include in Getting Started: YES