Documentation ¶
Index ¶
- type LogFormatFn
- type Option
- func WithErrorQueryLogLevel(level zerolog.Level) Option
- func WithLogFormat(f LogFormatFn) Option
- func WithLogger(logger *zerolog.Logger) Option
- func WithQueryLogLevel(level zerolog.Level) Option
- func WithSlowQueryLogLevel(level zerolog.Level) Option
- func WithSlowQueryThreshold(threshold time.Duration) Option
- type QueryHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogFormatFn ¶
type Option ¶
type Option func(*QueryHook)
Option is a function that configures a QueryHook.
func WithErrorQueryLogLevel ¶
WithErrorQueryLogLevel sets the log level for queries that result in an error.
func WithLogFormat ¶
func WithLogFormat(f LogFormatFn) Option
WithLogFormat sets the custom format for slog output.
func WithLogger ¶
WithLogger sets the *zerolog.Logger instance.
func WithQueryLogLevel ¶
WithQueryLogLevel sets the log level for general queries.
func WithSlowQueryLogLevel ¶
WithSlowQueryLogLevel sets the log level for slow queries.
func WithSlowQueryThreshold ¶
WithSlowQueryThreshold sets the duration threshold for identifying slow queries.
type QueryHook ¶
type QueryHook struct {
// contains filtered or unexported fields
}
QueryHook is a hook for Bun that enables logging with slog. It implements bun.QueryHook interface.
func NewQueryHook ¶
NewQueryHook initializes a new QueryHook with the given options.
func (*QueryHook) AfterQuery ¶
func (h *QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent)
AfterQuery is called after a query is executed. It logs the query based on its duration and whether it resulted in an error.
func (*QueryHook) BeforeQuery ¶
BeforeQuery is called before a query is executed.