Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithLoggedHttpAuthInfo(ctx context.Context, authInfo LogValuer) context.Context
- func ContextWithLogger(ctx context.Context, logger *Logger) context.Context
- func MemoryStatisticLogging(logger *Logger, level Level)
- func NewHttpAccessLogMiddleware(name string) func(next http.Handler) http.Handler
- func RunPeriodicMemoryLogging(ctx context.Context, logger *Logger, level Level, interval time.Duration, ...)
- func StartPeriodicMemoryLogging(ctx context.Context, logger *Logger, level Level, interval time.Duration, ...)
- type Attr
- type DiscardHandler
- type Handler
- type HandlerOptions
- type Level
- type Leveler
- type LogValuer
- type Logger
- func Default() *Logger
- func L(ctx context.Context) *Logger
- func LoggerFromContext(ctx context.Context) *Logger
- func NewDiscardLogger() *Logger
- func NewLogger(opts ...LoggerOption) *Logger
- func WithAttrs(ctx context.Context, attrs ...Attr) *Logger
- func WithDefaultAttrs(logger *Logger, attrs ...Attr) *Logger
- func WithName(logger *Logger, name string) *Logger
- type LoggerOption
- type LoggerOptions
- type OutputFormat
- type Record
- type ResponseWriter
- type Source
- type Value
Constants ¶
View Source
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError TimeKey = slog.TimeKey LevelKey = slog.LevelKey SourceKey = slog.SourceKey MessageKey = slog.MessageKey NameKey = "name" KindTime = slog.KindTime KindGroup = slog.KindGroup KindString = slog.KindString KindInt64 = slog.KindInt64 KindUint64 = slog.KindUint64 KindFloat64 = slog.KindFloat64 KindBool = slog.KindBool KindDuration = slog.KindDuration KindAny = slog.KindAny KindLogValuer = slog.KindLogValuer )
View Source
const (
AccessLogNameKey = "name"
)
Variables ¶
View Source
var ( NewTextHandler = slog.NewTextHandler NewJSONHandler = slog.NewJSONHandler New = slog.New SetDefault = slog.SetDefault GetDefault = slog.Default StringAttr = slog.String BoolAttr = slog.Bool Float64Attr = slog.Float64 AnyAttr = slog.Any DurationAttr = slog.Duration IntAttr = slog.Int Int64Attr = slog.Int64 Uint64Attr = slog.Uint64 Time = slog.Time Any = slog.Any String = slog.String GroupValue = slog.GroupValue StringValue = slog.StringValue Group = slog.Group )
View Source
var Err = ErrAttr
Functions ¶
func ContextWithLogger ¶
ContextWithLogger puts logger to context
func MemoryStatisticLogging ¶
Types ¶
type DiscardHandler ¶
type DiscardHandler struct{}
func NewDiscardHandler ¶
func NewDiscardHandler() *DiscardHandler
func (*DiscardHandler) WithAttrs ¶
func (h *DiscardHandler) WithAttrs(_ []Attr) Handler
func (*DiscardHandler) WithGroup ¶
func (h *DiscardHandler) WithGroup(_ string) Handler
type HandlerOptions ¶
type HandlerOptions = slog.HandlerOptions
type Logger ¶
func LoggerFromContext ¶
LoggerFromContext returns logger from context
func NewDiscardLogger ¶
func NewDiscardLogger() *Logger
func NewLogger ¶
func NewLogger(opts ...LoggerOption) *Logger
func WithDefaultAttrs ¶
WithDefaultAttrs returns logger with default attributes
type LoggerOption ¶
type LoggerOption func(*LoggerOptions)
func WithAddSource ¶
func WithAddSource(addSource bool) LoggerOption
WithAddSource logger option sets the add source option, which will add source file and line number to the log record
func WithCustomHandler ¶
func WithCustomHandler(handler Handler) LoggerOption
WithCustomHandler logger option sets the custom handler
func WithLevel ¶
func WithLevel(level string) LoggerOption
WithLevel logger option sets the log level, if not set, the default level is Info
func WithOutputFilePath ¶
func WithOutputFilePath(path string) LoggerOption
WithOutputFilePath set output file path
func WithOutputFormat ¶
func WithOutputFormat(format OutputFormat) LoggerOption
WithOutputFormat set output format
func WithSetDefault ¶
func WithSetDefault(setDefault bool) LoggerOption
WithSetDefault logger option sets the set default option, which will set the created logger as default logger
type LoggerOptions ¶
type OutputFormat ¶
type OutputFormat uint8
const ( OutputFormatJSON OutputFormat = iota OutputFormatTEXT )
func ParseOutputFormat ¶
func ParseOutputFormat(format string) (OutputFormat, error)
func (OutputFormat) String ¶
func (of OutputFormat) String() string
type ResponseWriter ¶
Click to show internal directories.
Click to hide internal directories.