Documentation ¶
Index ¶
- Constants
- func ToConfig(h slog.Handler) ([]byte, error)
- type Handler
- func (n *Handler) Enabled(_ context.Context, level slog.Level) bool
- func (n *Handler) Handle(ctx context.Context, record slog.Record) error
- func (n Handler) MarshalJSON() ([]byte, error)
- func (n *Handler) UnmarshalJSON(data []byte) error
- func (n *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (n *Handler) WithGroup(name string) slog.Handler
- type HandlerOption
- func WithColor() HandlerOption
- func WithDebugColor(color string) HandlerOption
- func WithErrorColor(color string) HandlerOption
- func WithFatalColor(color string) HandlerOption
- func WithGroupFilter(filter []string) HandlerOption
- func WithGroupTextOutputFormat(format string) HandlerOption
- func WithInfoColor(color string) HandlerOption
- func WithJSON() HandlerOption
- func WithLogLevel(level slog.Level) HandlerOption
- func WithShortLevels() HandlerOption
- func WithStdErr(err ...io.Writer) HandlerOption
- func WithStdOut(out ...io.Writer) HandlerOption
- func WithTextOutputFormat(format string) HandlerOption
- func WithTimeFormat(format string) HandlerOption
- func WithTraceColor(color string) HandlerOption
- func WithWarnColor(color string) HandlerOption
Constants ¶
const ( LevelTrace slog.Level = slog.LevelDebug - 2 LevelFatal slog.Level = slog.LevelError + 2 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandler(opts ...HandlerOption) *Handler
func NewHandlerFromConfig ¶
NewHandlerFromConfig will allow you to pass in the settings to slog.New(NewHandlerFromConfig). You will need to inclused the io.Writers in the NewHandlerFromConfig call as they are not serializable. Use ToConfig to get the config of your original Handler
func (Handler) MarshalJSON ¶
func (*Handler) UnmarshalJSON ¶
type HandlerOption ¶
type HandlerOption func(*Handler)
func WithColor ¶
func WithColor() HandlerOption
func WithDebugColor ¶
func WithDebugColor(color string) HandlerOption
func WithErrorColor ¶
func WithErrorColor(color string) HandlerOption
func WithFatalColor ¶
func WithFatalColor(color string) HandlerOption
func WithGroupFilter ¶
func WithGroupFilter(filter []string) HandlerOption
You can use this to filter out logs from specific groups
func WithGroupTextOutputFormat ¶
func WithGroupTextOutputFormat(format string) HandlerOption
func WithInfoColor ¶
func WithInfoColor(color string) HandlerOption
func WithJSON ¶
func WithJSON() HandlerOption
func WithLogLevel ¶
func WithLogLevel(level slog.Level) HandlerOption
func WithShortLevels ¶
func WithShortLevels() HandlerOption
func WithStdErr ¶
func WithStdErr(err ...io.Writer) HandlerOption
func WithStdOut ¶
func WithStdOut(out ...io.Writer) HandlerOption
func WithTextOutputFormat ¶
func WithTextOutputFormat(format string) HandlerOption
WithTextOutputFormat sets the format for the group output. The order of the fields are: 1. Record Level (Debug, Info, Warn, Error) 2. Record Time 3. Record Message
The default format is "[%s] %s - %s\n". If you want to rearrange the fields, you can use the indexes: "%[3]s %[1]s %[2]\n" This will output "{Record Message} {Record Level} {Record Time}\n"
User must provide newline in format
func WithTimeFormat ¶
func WithTimeFormat(format string) HandlerOption
func WithTraceColor ¶
func WithTraceColor(color string) HandlerOption
func WithWarnColor ¶
func WithWarnColor(color string) HandlerOption