loge

package
v0.0.62 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
	LevelFatal = 12
)
View Source
const (
	// DefaultTimeLayout the default time layout;
	DefaultTimeLayout = time.RFC3339
)

Variables

This section is empty.

Functions

func New

func New(ss ...Setting) *slog.Logger

New create a new slog.Logger

Types

type Attr

type Attr = slog.Attr

type DevConfig added in v0.0.43

type DevConfig = struct {
	// Max number of printed elements in slice.
	MaxSlice uint `json:"maxslice" yaml:"maxslice" toml:"maxslice"`

	// If the attributes should be sorted by keys
	SortKeys bool `json:"sortkeys" yaml:"sortkeys" toml:"sortkeys"`

	// Add blank line after each log
	NewLine bool `json:"newline" yaml:"newline" toml:"newline"`

	// Indent \n in strings
	Indent bool `json:"indent" yaml:"indent" toml:"indent"`

	// Set color for Debug level, default: devslog.Blue
	DebugColor devslog.Color `json:"debugcolor" yaml:"debugcolor" toml:"debugcolor"`

	// Set color for Info level, default: devslog.Green
	InfoColor devslog.Color `json:"infocolor" yaml:"infocolor" toml:"infocolor"`

	// Set color for Warn level, default: devslog.Yellow
	WarnColor devslog.Color `json:"warncolor" yaml:"warncolor" toml:"warncolor"`

	// Set color for Error level, default: devslog.Red
	ErrorColor devslog.Color `json:"errorcolor" yaml:"errorcolor" toml:"errorcolor"`

	// Max stack trace frames when unwrapping errors
	MaxTrace uint `json:"maxtrace" yaml:"maxtrace" toml:"maxtrace"`

	// Use method String() for formatting value
	Formatter bool `json:"formatter" yaml:"formatter" toml:"formatter"`
}

type Format

type Format int
const (
	// FormatJSON json format
	FormatJSON Format = iota
	// FormatText text format
	FormatText
	// FormatTint tint format
	FormatTint
	// FormatDev dev format
	FormatDev
)

func (Format) String

func (i Format) String() string

type Handler

type Handler = slog.Handler

type HandlerOptions

type HandlerOptions = slog.HandlerOptions

type Level

type Level = slog.Level

type Leveler

type Leveler = slog.Leveler

type LumberjackConfig

type LumberjackConfig = struct {
	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int `json:"maxsize" yaml:"maxsize" toml:"maxsize"`

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int `json:"maxage" yaml:"maxage" toml:"maxage"`

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int `json:"maxbackups" yaml:"maxbackups" toml:"maxbackups"`

	// LocalTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool `json:"localtime" yaml:"localtime" toml:"localtime"`

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool `json:"compress" yaml:"compress" toml:"compress"`
}

type Option

type Option struct {
	OutputPath       string
	FileName         string
	Format           Format
	TimeLayout       string
	DisableConsole   bool
	Level            Leveler
	ReplaceAttr      func(groups []string, attr Attr) Attr
	AddSource        bool
	LumberjackConfig *LumberjackConfig
	DevConfig        *DevConfig
	NoColor          bool
	UseDefault       bool
}

Option custom setup config

type Setting

type Setting = func(*Option)

func WithAddSource

func WithAddSource() Setting

WithAddSource add source info to log

func WithDevConfig added in v0.0.43

func WithDevConfig(config *DevConfig) Setting

WithDevConfig set dev config

func WithDisableConsole

func WithDisableConsole() Setting

WithDisableConsole WithEnableConsole write log to os.Stdout or os.Stderr

func WithFile

func WithFile(file string) Setting

WithFile write log to some File

func WithFormat

func WithFormat(format Format) Setting

WithFormat custom format

func WithLevel

func WithLevel(level Leveler) Setting

WithLevel custom log level

func WithLumberjack

func WithLumberjack(filename string, config *LumberjackConfig) Setting

WithLumberjack write log to some File with rotation

func WithNoColor

func WithNoColor() Setting

WithNoColor disable color

func WithPath

func WithPath(path string) Setting

WithPath custom path to write log

func WithReplaceAttr

func WithReplaceAttr(replaceAttr func(groups []string, attr Attr) Attr) Setting

WithReplaceAttr custom replaceAttr

func WithTimeLayout

func WithTimeLayout(timeLayout string) Setting

WithTimeLayout custom time format

func WithUseDefault

func WithUseDefault() Setting

WithUseDefault use output as slog.Default()

type TintOptions

type TintOptions = tint.Options

Jump to

Keyboard shortcuts

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