Documentation
¶
Overview ¶
Package entslog for entgo.io/ent
Package entslog for entgo.io/ent
Package entslog for entgo.io/ent
Index ¶
- func New(dri dialect.Driver, ss ...Setting) dialect.Driver
- type FilterAttrs
- type Handler
- type Option
- type Setting
- func WithDefaultLevel(level slog.Leveler) Setting
- func WithError() Setting
- func WithErrorLevel(level slog.Leveler) Setting
- func WithFilter(filter func(context.Context, ...slog.Attr) []slog.Attr) Setting
- func WithLogger(logger *slog.Logger) Setting
- func WithTrace(trace func(context.Context) string) Setting
- type SlogDriver
- func (d *SlogDriver) BeginTx(ctx context.Context, opts *sql.TxOptions) (dialect.Tx, error)
- func (d *SlogDriver) Close() error
- func (d *SlogDriver) Dialect() string
- 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
- type TraceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FilterAttrs ¶
FilterAttrs defines a function to filter out attributes from log entries.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option defines configuration options for the logging handler.
type Setting ¶ added in v3.0.2
type Setting = func(*Option)
Setting is a type alias for the settings.Setting type.
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 WithError ¶
func WithError() Setting
WithError 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.
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 ¶
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 WithLogger ¶
WithLogger specifies the logger to be used for logging. If not specified, the default logger will be used.
- `logger`: The logger to be used for logging.
Returns a function that accepts an `*Option` parameter, modifies it by setting the logger, and returns the updated `*Option` pointer.
func WithTrace ¶
WithTrace 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.
- `trace`: 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.
type SlogDriver ¶
type SlogDriver struct { Handler // log function. defaults to slog.Default() // contains filtered or unexported fields }
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) Close ¶
func (d *SlogDriver) Close() error
func (*SlogDriver) Dialect ¶
func (d *SlogDriver) Dialect() string
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 { 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.