sloge

package
v0.0.87 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 11 Imported by: 2

README

Sloge Package

Introduction

This package is an enhancement for 'log/slog' and provides richer functionality for 'log/slog'.

Usage

import "github.com/origadmin/toolkits/sloge"

func main(){
    l := sloge.New()
    l.Info("hello world")
}

Documentation

Overview

Package sloge implements the functions, types, and interfaces for the module.

Package sloge implements the functions, types, and interfaces for the module.

Package sloge implements the functions, types, and interfaces for the module.

Package sloge implements the functions, types, and interfaces for the module.

Index

Constants

View Source
const (
	KindAny       = slog.KindAny
	KindBool      = slog.KindBool
	KindDuration  = slog.KindDuration
	KindFloat64   = slog.KindFloat64
	KindGroup     = slog.KindGroup
	KindInt64     = slog.KindInt64
	KindLogValuer = slog.KindLogValuer
	KindString    = slog.KindString
	KindTime      = slog.KindTime
	KindUint64    = slog.KindUint64
	LevelDebug    = slog.LevelDebug
	LevelError    = slog.LevelError
	LevelInfo     = slog.LevelInfo
	LevelKey      = slog.LevelKey
	LevelWarn     = slog.LevelWarn
	MessageKey    = slog.MessageKey
	SourceKey     = slog.SourceKey
	TimeKey       = slog.TimeKey
)

slog is a wrapper around slog

View Source
const (
	Black        = devslog.Black
	Blue         = devslog.Blue
	Cyan         = devslog.Cyan
	Green        = devslog.Green
	Magenta      = devslog.Magenta
	Red          = devslog.Red
	UnknownColor = devslog.UnknownColor
	White        = devslog.White
	Yellow       = devslog.Yellow
)

devslog is a wrapper around devslog

View Source
const (
	// DefaultTimeLayout the default time layout;
	DefaultTimeLayout = time.RFC3339
)
View Source
const (
	LevelFatal = 12
)

Variables

View Source
var (
	Any               = slog.Any
	AnyValue          = slog.AnyValue
	Bool              = slog.Bool
	BoolValue         = slog.BoolValue
	Debug             = slog.Debug
	DebugContext      = slog.DebugContext
	Default           = slog.Default
	Duration          = slog.Duration
	DurationValue     = slog.DurationValue
	Error             = slog.Error
	ErrorContext      = slog.ErrorContext
	Float64           = slog.Float64
	Float64Value      = slog.Float64Value
	Group             = slog.Group
	GroupValue        = slog.GroupValue
	Info              = slog.Info
	InfoContext       = slog.InfoContext
	Int               = slog.Int
	Int64             = slog.Int64
	Int64Value        = slog.Int64Value
	IntValue          = slog.IntValue
	Log               = slog.Log
	LogAttrs          = slog.LogAttrs
	NewJSONHandler    = slog.NewJSONHandler
	NewLogLogger      = slog.NewLogLogger
	NewRecord         = slog.NewRecord
	NewTextHandler    = slog.NewTextHandler
	SetDefault        = slog.SetDefault
	SetLogLoggerLevel = slog.SetLogLoggerLevel
	String            = slog.String
	StringValue       = slog.StringValue
	Time              = slog.Time
	TimeValue         = slog.TimeValue
	Uint64            = slog.Uint64
	Uint64Value       = slog.Uint64Value
	Warn              = slog.Warn
	WarnContext       = slog.WarnContext
	With              = slog.With
)
View Source
var (
	Err            = tint.Err
	NewTintHandler = tint.NewHandler
)

tint is a wrapper around tint

View Source
var (
	// NewDevSlogHandler is a wrapper around devslog.NewHandler
	NewDevSlogHandler = devslog.NewHandler
)

Functions

This section is empty.

Types

type Attr added in v0.0.87

type Attr = slog.Attr

slog is a wrapper around slog

type Color added in v0.0.87

type Color = devslog.Color

devslog is a wrapper around devslog

type DevConfig added in v0.0.87

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

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

	// 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 Color `json:"debug_color" yaml:"debug_color" toml:"debug_color"`

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

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

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

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

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

type DevSlogOptions added in v0.0.87

type DevSlogOptions = devslog.Options

devslog is a wrapper around devslog

type Format added in v0.0.38

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 added in v0.0.87

func (i Format) String() string

type Handler added in v0.0.87

type Handler = slog.Handler

slog is a wrapper around slog

type HandlerOptions added in v0.0.87

type HandlerOptions = slog.HandlerOptions

slog is a wrapper around slog

type JSONHandler added in v0.0.87

type JSONHandler = slog.JSONHandler

slog is a wrapper around slog

type Kind added in v0.0.87

type Kind = slog.Kind

slog is a wrapper around slog

type Level added in v0.0.87

type Level = slog.Level

slog is a wrapper around slog

type LevelVar added in v0.0.87

type LevelVar = slog.LevelVar

slog is a wrapper around slog

type Leveler added in v0.0.87

type Leveler = slog.Leveler

slog is a wrapper around slog

type LogValuer added in v0.0.87

type LogValuer = slog.LogValuer

slog is a wrapper around slog

type Logger added in v0.0.87

type Logger = slog.Logger

slog is a wrapper around slog

func New

func New(ss ...Setting) *Logger

New create a new slog.Logger

type LumberjackConfig added in v0.0.87

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:"max_size" yaml:"max_size" toml:"max_size"`

	// 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:"max_age" yaml:"max_age" toml:"max_age"`

	// 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:"max_backups" yaml:"max_backups" toml:"max_backups"`

	// 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 LumberjackLogger added in v0.0.87

type LumberjackLogger = lumberjack.Logger

LumberjackLogger is a wrapper around lumberjack.Logger

type Option

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

Option custom setup config

type Record added in v0.0.87

type Record = slog.Record

slog is a wrapper around slog

type Setting added in v0.0.87

type Setting = func(*Option)

func WithAddSource added in v0.0.87

func WithAddSource() Setting

WithAddSource add source info to log

func WithConsole added in v0.0.87

func WithConsole(set bool) Setting

WithConsole set the log to console or /dev/null

func WithDefault added in v0.0.87

func WithDefault(set bool) Setting

WithDefault use output as slog.Default()

func WithDevConfig added in v0.0.87

func WithDevConfig(config *DevConfig) Setting

WithDevConfig set dev config

func WithFile

func WithFile(file string) Setting

WithFile write log to some File

func WithFormat added in v0.0.87

func WithFormat(format Format) Setting

WithFormat custom format

func WithLevel added in v0.0.87

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 added in v0.0.87

func WithNoColor() Setting

WithNoColor disable color

func WithPath added in v0.0.87

func WithPath(path string) Setting

WithPath custom path to write log

func WithReplaceAttr added in v0.0.87

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

WithReplaceAttr custom replaceAttr

func WithTimeLayout

func WithTimeLayout(timeLayout string) Setting

WithTimeLayout custom time format

type Source added in v0.0.87

type Source = slog.Source

slog is a wrapper around slog

type TextHandler added in v0.0.87

type TextHandler = slog.TextHandler

slog is a wrapper around slog

type TintOptions added in v0.0.87

type TintOptions = tint.Options

TintOptions is a wrapper around tint.Options

type Value added in v0.0.87

type Value = slog.Value

slog is a wrapper around slog

Jump to

Keyboard shortcuts

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