logger

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = New(CONSOLE_HANDLER, Options{
	Development:  false,
	Debug:        false,
	EnableCaller: false,
	SkipCaller:   3,
})

DefaultLogger is the default Log with console handler.

Functions

This section is empty.

Types

type Environment

type Environment uint8
const (
	DEVELOPMENT Environment = iota
	PRODUCTION
	RELEASE
)

func (Environment) String

func (e Environment) String() string

type HandleType

type HandleType uint8
const (
	CONSOLE_HANDLER HandleType = iota
	TEXT_HANDLER
	JSON_HANDLER
)

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewConsoleHandler

func NewConsoleHandler(opts *slog.HandlerOptions) *Handler

func (*Handler) Enabled

func (h *Handler) Enabled(ctx context.Context, level slog.Level) bool

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, r slog.Record) error

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

type Log

type Log struct {
	// contains filtered or unexported fields
}

func (*Log) Debug

func (l *Log) Debug(msg string, keyValues ...any)

func (*Log) DebugContext

func (l *Log) DebugContext(ctx context.Context, msg string, keyValues ...any)

func (*Log) Error

func (l *Log) Error(msg string, keyValues ...any)

func (*Log) ErrorContext

func (l *Log) ErrorContext(ctx context.Context, msg string, keyValues ...any)

func (*Log) Fatal

func (l *Log) Fatal(msg string, keyValues ...any)

func (*Log) FatalContext

func (l *Log) FatalContext(ctx context.Context, msg string, keyValues ...any)

func (*Log) Info

func (l *Log) Info(msg string, keyValues ...any)

func (*Log) InfoContext

func (l *Log) InfoContext(ctx context.Context, msg string, keyValues ...any)

func (*Log) Warn

func (l *Log) Warn(msg string, keyValues ...any)

func (*Log) WarnContext

func (l *Log) WarnContext(ctx context.Context, msg string, keyValues ...any)

type Logger

type Logger interface {
	// Debug show debug log
	Debug(msg string, args ...any)
	// DebugContext show debug log with passing context
	DebugContext(ctx context.Context, msg string, args ...any)
	// Info show info log
	Info(msg string, args ...any)
	// InfoContext show info log with passing context
	InfoContext(ctx context.Context, msg string, args ...any)
	// Warn show warn log
	Warn(msg string, args ...any)
	// WarnContext show warn log with passing context
	WarnContext(ctx context.Context, msg string, args ...any)
	// Error show error log
	Error(msg string, args ...any)
	// ErrorContext show error log with passing context
	ErrorContext(ctx context.Context, msg string, args ...any)
	// Fatal show error log and exit application with os.Exit(1)
	Fatal(msg string, args ...any)
	// FatalContext show error log with passing context and exit application with os.Exit(1)
	FatalContext(ctx context.Context, msg string, args ...any)
}

func New

func New(
	handler HandleType,
	loggerOption Options,
) Logger

New create new Logger

type Options

type Options struct {
	Development  bool // Development add development details of machine
	Debug        bool // Debug show debug devel message
	EnableCaller bool // EnableCaller show caller in line code
	// SkipCaller skip caller level of CallerFrames
	// https://github.com/golang/go/issues/59145#issuecomment-1481920720
	SkipCaller        int
	CustomSlog        *slog.Logger      // CustomSlog set custom slog.Logger
	CustomJsonHandler *slog.JSONHandler // CustomJsonHandler set custom slog.JsonHandler
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL