Documentation ¶
Index ¶
- Constants
- func New(options ...Option) *logger
- type LogType
- type Option
- func SetLogLevel(key LogType, level slog.Level) Option
- func WithContextFunc(slogAttrName string, ...) Option
- func WithContextValue(slogAttrName string, contextKey any) Option
- func WithErrorField(field string) Option
- func WithHandler(handler slog.Handler) Option
- func WithIgnoreTrace() Option
- func WithLogger(log *slog.Logger) Optiondeprecated
- func WithRecordNotFoundError() Option
- func WithSlowThreshold(threshold time.Duration) Option
- func WithSourceField(field string) Option
- func WithTraceAll() Option
Constants ¶
const ( ErrorLogType LogType = "sql_error" SlowQueryLogType LogType = "slow_query" DefaultLogType LogType = "default" SourceField = "file" ErrorField = "error" QueryField = "query" DurationField = "duration" SlowQueryField = "slow_query" RowsField = "rows" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(l *logger)
func SetLogLevel ¶
SetLogLevel sets a new slog.Level for a LogType.
func WithContextFunc ¶ added in v1.4.0
func WithContextFunc(slogAttrName string, slogValueFunc func(ctx context.Context) (slog.Value, bool)) Option
WithContextFunc adds an attribute with the given name and slog.Value returned by the given function if the function returns true. No attribute will be added if the function returns false. Use this over WithContextValue if your context keys are not strings or only accessible via functions.
func WithContextValue ¶ added in v1.1.0
WithContextValue adds a context value to the log
func WithErrorField ¶
WithErrorField defines the field to set the error
func WithHandler ¶ added in v1.3.0
WithHandler defines a custom logger to use
func WithIgnoreTrace ¶
func WithIgnoreTrace() Option
WithIgnoreTrace disables the tracing of SQL queries by the slogger
func WithLogger
deprecated
func WithRecordNotFoundError ¶
func WithRecordNotFoundError() Option
WithRecordNotFoundError allows the slogger to log gorm.ErrRecordNotFound errors
func WithSlowThreshold ¶
WithSlowThreshold defines the threshold above which a sql query is considered slow
func WithSourceField ¶
WithSourceField defines the field to set the file name and line number of the current file
func WithTraceAll ¶
func WithTraceAll() Option
WithTraceAll enables mode which logs all SQL messages.