Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithLogger(ctx context.Context, l *slog.Logger) context.Context
- func ExtractLoggerFromContext(ctx context.Context) *slog.Logger
- func NewHandler(options *options) slog.Handler
- func NewHandlerOptions(level slog.Leveler, opt *Options) slog.HandlerOptions
- func NewLogger(opts ...Option) *slog.Logger
- type CLIHandler
- type CLIHandlerOptions
- type Option
- func WithAppName(name string) Option
- func WithDisableSource() Option
- func WithDisableTime() Option
- func WithFormat(format string) Option
- func WithFullSource() Option
- func WithLevel(level string) Option
- func WithOrganization(name string) Option
- func WithOutput(output string) Option
- func WithTracing() Option
- func WithWriter(w io.Writer) Option
- type Options
- type TracingHandler
- func (h *TracingHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *TracingHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *TracingHandler) Handler() slog.Handler
- func (h *TracingHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *TracingHandler) WithGroup(name string) slog.Handler
Constants ¶
View Source
const TraceIDKey = "trace_id"
Variables ¶
View Source
var Colors = map[slog.Level]*color.Color{ slog.LevelDebug: color.New(color.FgWhite), slog.LevelInfo: color.New(color.FgBlue), slog.LevelWarn: color.New(color.FgYellow), slog.LevelError: color.New(color.FgRed), }
View Source
var Strings = map[slog.Level]string{ slog.LevelDebug: "•", slog.LevelInfo: "•", slog.LevelWarn: "•", slog.LevelError: "⨯", }
Functions ¶
func ContextWithLogger ¶
ContextWithLogger adds logger to context.
func ExtractLoggerFromContext ¶
ExtractLoggerFromContext returns logger from context.
func NewHandler ¶
NewHandler create new slog handler. Default stdout with json handler and info level
func NewHandlerOptions ¶
func NewHandlerOptions(level slog.Leveler, opt *Options) slog.HandlerOptions
NewHandlerOptions create new options with level
Types ¶
type CLIHandler ¶
func NewCLIHandler ¶
func NewCLIHandler( out io.Writer, opts *CLIHandlerOptions, ) *CLIHandler
type CLIHandlerOptions ¶
type CLIHandlerOptions struct { DisableColor bool slog.HandlerOptions }
type Option ¶
type Option func(o *options)
Option is an application option.
func WithFormat ¶
WithFormat set output format. Default "json"
func WithOrganization ¶
WithOrganization set name of organization
type Options ¶
type Options struct { DisableSource bool FullSource bool DisableTime bool DisableColor bool // for cli // for format Name string Organization string Context string }
Options
type TracingHandler ¶
type TracingHandler struct {
// contains filtered or unexported fields
}
TracingHandler slog with traces
func NewTracingHandler ¶
func NewTracingHandler(h slog.Handler) *TracingHandler
NewTracingHandler create tracing handler
func (*TracingHandler) Enabled ¶
Enabled implements Handler.Enabled by reporting whether level is at least as large as h's level.
func (*TracingHandler) Handler ¶
func (h *TracingHandler) Handler() slog.Handler
Handler returns the Handler wrapped by handler.
Click to show internal directories.
Click to hide internal directories.