Documentation
¶
Overview ¶
Package slogx implements the functions, types, and interfaces for the module.
Package slogx contains generated code by adptool.
Package slogx contains the go:generate directives for adptool. This file exists to ensure the generated output is named log.adapter.go.
Package slogx implements enhanced logging functions for slog
Index ¶
- Constants
- Variables
- func Any(key string, value any) slog.Attr
- func AnyValue(v any) slog.Value
- func Bool(key string, v bool) slog.Attr
- func BoolValue(v bool) slog.Value
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Default() *slog.Logger
- func Duration(key string, v time.Duration) slog.Attr
- func DurationValue(v time.Duration) slog.Value
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func Float64(key string, v float64) slog.Attr
- func Float64Value(v float64) slog.Value
- func Group(key string, args ...any) slog.Attr
- func GroupValue(as ...slog.Attr) slog.Value
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func Int(key string, value int) slog.Attr
- func Int64(key string, value int64) slog.Attr
- func Int64Value(v int64) slog.Value
- func IntValue(v int) slog.Value
- func Log(ctx context.Context, level slog.Level, msg string, args ...any)
- func LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
- func New(options ...Option) *slog.Logger
- func NewDebug(options ...Option) *slog.Logger
- func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) *slog.JSONHandler
- func NewLogLogger(h slog.Handler, level slog.Level) *log.Logger
- func NewRecord(t time.Time, level slog.Level, msg string, pc uintptr) slog.Record
- func NewSlog(h slog.Handler) *slog.Logger
- func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) *slog.TextHandler
- func NewTintHandler(w io.Writer, opts *tint.Options) slog.Handler
- func SetDefault(l *slog.Logger)
- func SetLogLoggerLevel(level slog.Level) (oldLevel slog.Level)
- func String(key, value string) slog.Attr
- func StringValue(value string) slog.Value
- func Time(key string, v time.Time) slog.Attr
- func TimeValue(v time.Time) slog.Value
- func TintAttr(color uint8, attr slog.Attr) slog.Attr
- func TintErr(err error) slog.Attr
- func Uint64(key string, v uint64) slog.Attr
- func Uint64Value(v uint64) slog.Value
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- func With(args ...any) *slog.Logger
- type Attr
- type Color
- type DevslogOptions
- type Format
- type Handler
- type HandlerOptions
- type JSONHandler
- type Kind
- type Level
- type LevelVar
- type Leveler
- type LogValuer
- type Logger
- type LumberjackLogger
- type Option
- func WithAddSource() Option
- func WithConsole(set bool) Option
- func WithConsoleOnly() Option
- func WithDefault(set bool) Option
- func WithDevConfig(config *DevslogOptions) Option
- func WithFile(file string) Option
- func WithFormat(format Format) Option
- func WithLevel(level Leveler) Option
- func WithLumberjack(lumberjackLogger *LumberjackLogger) Option
- func WithNoColor() Option
- func WithOutputFile(file string) Option
- func WithReplaceAttr(replaceAttr func(groups []string, attr Attr) Attr) Option
- func WithTimeLayout(timeLayout string) Option
- type Options
- type Record
- type Source
- type TextHandler
- type TintOptions
- type Value
Constants ¶
const ( Black = devslog.Black Blue = devslog.Blue Cyan = devslog.Cyan Green = devslog.Green Magenta = devslog.Magenta Red = devslog.Red UnknownColor = devslog.UnknownColor White = devslog.White Yellow = devslog.Yellow KindAny = slog.KindAny KindBool = slog.KindBool KindDuration = slog.KindDuration KindFloat64 = slog.KindFloat64 KindGroup = slog.KindGroup KindInt64 = slog.KindInt64 KindLogValuer = slog.KindLogValuer KindString = slog.KindString KindTime = slog.KindTime KindUint64 = slog.KindUint64 LevelDebug = slog.LevelDebug LevelError = slog.LevelError LevelInfo = slog.LevelInfo LevelKey = slog.LevelKey LevelWarn = slog.LevelWarn MessageKey = slog.MessageKey SourceKey = slog.SourceKey TimeKey = slog.TimeKey )
const ( // DefaultTimeLayout the default time layout; DefaultTimeLayout = time.DateTime )
const (
LevelFatal = slog.Level(12)
)
LevelFatal is a custom log level, demonstrating how to extend slog's levels.
Variables ¶
var DiscardHandler = slog.DiscardHandler
Functions ¶
func Float64Value ¶
func Int64Value ¶
func New ¶
New creates a new slog.Logger by applying the provided functional options. This function is a refactored, cleaner version of the original NewSlogx, preserving all functionality while improving maintainability.
func NewDebug ¶
NewDebug creates a new slog.Logger with debug level. It's a convenient shortcut for New(WithLevel(slog.LevelDebug)).
func NewJSONHandler ¶
func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) *slog.JSONHandler
func NewTextHandler ¶
func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) *slog.TextHandler
func SetDefault ¶
func StringValue ¶
func Uint64Value ¶
Types ¶
type DevslogOptions ¶ added in v0.3.20
type HandlerOptions ¶
type HandlerOptions = slog.HandlerOptions
type JSONHandler ¶
type JSONHandler = slog.JSONHandler
type LumberjackLogger ¶
type LumberjackLogger = lumberjack.Logger
type Option ¶
type Option = func(*Options)
func WithConsole ¶
WithConsole set the log to console or /dev/null
func WithLumberjack ¶
func WithLumberjack(lumberjackLogger *LumberjackLogger) Option
WithLumberjack write log to some File with rotation
func WithOutputFile ¶ added in v0.3.20
WithOutputFile write log to some File
func WithReplaceAttr ¶
WithReplaceAttr custom replaceAttr
func WithTimeLayout ¶
WithTimeLayout custom time format
type Options ¶
type Options struct {
Output string
Format Format
TimeLayout string
Console bool
Level Leveler
ReplaceAttr func(groups []string, attr Attr) Attr
AddSource bool
LumberjackLogger *LumberjackLogger
DevslogOptions *DevslogOptions
NoColor bool
Default bool
}
Options custom setup config
func DefaultOptions ¶ added in v0.3.20
func DefaultOptions() Options
type TextHandler ¶
type TextHandler = slog.TextHandler