Documentation
¶
Overview ¶
Package entslog provides logging capabilities initWith ent entities.
Index ¶
- Variables
- func New(logger *slog.Logger, opts ...func(*Option) *Option) func(dialect.Driver) dialect.Driver
- func WithDefaultLevel(level slog.Leveler) func(*Option) *Option
- func WithErrorLevel(level slog.Leveler) func(*Option) *Option
- func WithFilter(filter func(context.Context, ...slog.Attr) []slog.Attr) func(*Option) *Option
- func WithGenerateID(generateID func(context.Context) string) func(*Option) *Option
- func WithHandleError(handleError bool) func(*Option) *Option
- type Handler
- type Option
- type SlogDriver
- func (d *SlogDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)
- func (d *SlogDriver) Exec(ctx context.Context, query string, args, v any) error
- func (d *SlogDriver) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (d *SlogDriver) Query(ctx context.Context, query string, args, v any) error
- func (d *SlogDriver) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (d *SlogDriver) Tx(ctx context.Context) (dialect.Tx, error)
- type SlogTx
- func (d *SlogTx) Commit() error
- func (d *SlogTx) Exec(ctx context.Context, query string, args, v any) error
- func (d *SlogTx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (d *SlogTx) Query(ctx context.Context, query string, args, v any) error
- func (d *SlogTx) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (d *SlogTx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
var DefaultOption = Option{ // contains filtered or unexported fields }
DefaultOption provides the default configuration options for the logging handler.
Functions ¶
func New ¶
New gets a init and an optional logging function, and returns a new slog-init that prints all outgoing operations.
func WithDefaultLevel ¶
WithDefaultLevel sets the default log level for the given logging options.
- `level`: The log level to be set as the default.
Returns a function that accepts an `*Option` parameter, modifies it by setting the default log level, and returns the updated `*Option` pointer.
func WithErrorLevel ¶
WithErrorLevel sets the error log level and enables handling of errors for the given logging options.
- `level`: The log level to be set for error logging.
Returns a function that accepts an `*Option` parameter, modifies it by setting the error log level and enabling error handling, then returns the updated `*Option` pointer.
func WithFilter ¶ added in v2.0.2
WithFilter specifies a list of attribute names to filter out from logged messages for the given logging options.
- `attrs`: A variadic list of strings representing attribute names to be filtered.
Returns a function that accepts an `*Option` parameter, modifies it by setting the list of filtered attributes, and returns the updated `*Option` pointer.
func WithGenerateID ¶
WithGenerateID assigns a custom ID generation function for the given logging options. This function will be used to generate unique IDs for log entries within a given context.
- `generateID`: A function that accepts a `context.Context` and returns a string representing the generated ID.
Returns a function that accepts an `*Option` parameter, modifies it by setting the custom ID generation function, and returns the updated `*Option` pointer.
func WithHandleError ¶
WithHandleError explicitly enables or disables error handling for the given logging options.
- `handleError`: A boolean indicating whether to enable (true) or disable (false) error handling.
Returns a function that accepts an `*Option` parameter, modifies it by setting the error handling flag, and returns the updated `*Option` pointer.
Types ¶
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option defines configuration options for the logging handler.
type SlogDriver ¶
type SlogDriver struct {
dialect.Driver // underlying init.
Handler // log function. defaults to slog.Default()
}
SlogDriver is a init that logs all init operations.
func (*SlogDriver) BeginTx ¶
BeginTx adds an log-id for the transaction and calls the underlying init BeginTx command if it is supported.
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 init ExecContext method if it is supported.
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 init QueryContext method if it is supported.
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) ExecContext ¶
ExecContext logs its params and calls the underlying transaction ExecContext method if it is supported.
func (*SlogTx) QueryContext ¶
QueryContext logs its params and calls the underlying transaction QueryContext method if it is supported.