entslog

package module
v0.0.0-...-b489550 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 6 Imported by: 0

README ¶

entslog: slog ent handler

tag Go Version GoDoc Build Status Go report Coverage Contributors License

A ent Handler for slog Go library.

Installation

go get github.com/godcong/entslog@latest

Compatibility: go >= 1.21

No breaking changes will be made to exported APIs before v1.0.0.

💡 Usage

GoDoc: https://pkg.go.dev/github.com/godcong/entslog

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var DefaultOption = Option{}

Functions ¶

func New ¶

func New(logger *slog.Logger, ops ...Option) func(dialect.Driver) dialect.Driver

New gets a driver and an optional logging function, and returns a new slog-driver that prints all outgoing operations.

Types ¶

type Handler ¶

type Handler struct {
	// contains filtered or unexported fields
}

type Option ¶

type Option struct {
	DefaultLevel slog.Leveler
	ErrorLevel   slog.Leveler
	HandleError  bool
	FilterAttrs  []string
}

type SlogDriver ¶

type SlogDriver struct {
	dialect.Driver // underlying driver.
	// log function. defaults to slog.Default()
	Handler
}

SlogDriver is a driver that logs all driver operations.

func (*SlogDriver) BeginTx ¶

func (d *SlogDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)

BeginTx adds an log-id for the transaction and calls the underlying driver BeginTx command if it is supported.

func (*SlogDriver) Exec ¶

func (d *SlogDriver) Exec(ctx context.Context, query string, args, v any) error

Exec logs its params and calls the underlying driver Exec method.

func (*SlogDriver) ExecContext ¶

func (d *SlogDriver) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext logs its params and calls the underlying driver ExecContext method if it is supported.

func (*SlogDriver) Query ¶

func (d *SlogDriver) Query(ctx context.Context, query string, args, v any) error

Query logs its params and calls the underlying driver Query method.

func (*SlogDriver) QueryContext ¶

func (d *SlogDriver) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext logs its params and calls the underlying driver QueryContext method if it is supported.

func (*SlogDriver) Tx ¶

func (d *SlogDriver) Tx(ctx context.Context) (dialect.Tx, error)

Tx adds an log-id for the transaction and calls the underlying driver Tx command.

type SlogTx ¶

type SlogTx struct {
	dialect.Tx // underlying transaction.
	Handler
	// contains filtered or unexported fields
}

SlogTx is a transaction implementation that logs all transaction operations.

func (*SlogTx) Commit ¶

func (d *SlogTx) Commit() error

Commit logs this step and calls the underlying transaction Commit method.

func (*SlogTx) Exec ¶

func (d *SlogTx) Exec(ctx context.Context, query string, args, v any) error

Exec logs its params and calls the underlying transaction Exec method.

func (*SlogTx) ExecContext ¶

func (d *SlogTx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext logs its params and calls the underlying transaction ExecContext method if it is supported.

func (*SlogTx) Query ¶

func (d *SlogTx) Query(ctx context.Context, query string, args, v any) error

Query logs its params and calls the underlying transaction Query method.

func (*SlogTx) QueryContext ¶

func (d *SlogTx) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)

QueryContext logs its params and calls the underlying transaction QueryContext method if it is supported.

func (*SlogTx) Rollback ¶

func (d *SlogTx) Rollback() error

Rollback logs this step and calls the underlying transaction Rollback method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL