clog

package
v0.0.0-...-6d40105 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 12 Imported by: 0

README

日志处理

基础功能

  • 支持基础的日志信息:
  • 支持不同的日志级别
  • 支持自定义配置
  • 支持输出到标准输出和保存到文件

高级功能

  • 支持多种日志格式
  • 支持按级别分类输出
  • 支持结构化日志
  • 支持日志轮转
  • 具备Hook能力

额外可选功能

  • 支持颜色输出
  • 兼容标准库log
  • 支持输出到不同位置

Documentation

Index

Constants

View Source
const (
	FmtEmptySeparate = ""
)

Variables

View Source
var LevelNameMapping = map[Level]string{
	DebugLevel: "DEBUG",
	InfoLevel:  "INFO",
	WarnLevel:  "WARN",
	ErrorLevel: "ERROR",
	PanicLevel: "PANiC",
	FatalLevel: "Fatal",
}

LevelNameMapping log level string name mapping

Functions

func Debug

func Debug(args ...interface{})

std logger

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func New

func New(opts ...Option) *logger

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func SetOptions

func SetOptions(opts ...Option)

func StdLogger

func StdLogger() *logger

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Writer

func Writer() io.Writer

Types

type Entry

type Entry struct {
	Buffer *bytes.Buffer
	Map    map[string]interface{}
	Level  Level
	Time   time.Time
	File   string
	Line   int
	Func   string
	Format string
	Args   []interface{}
	// contains filtered or unexported fields
}

Entry 将日志记录到支持的输出

type Formatter

type Formatter interface {
	// Maybe in async goroutine
	// Please write the result to buffer
	Format(entry *Entry) error
}

Formatter 自定义日志输出格式

type JsonFormatter

type JsonFormatter struct {
	IgnoreBasicFields bool
}

func (*JsonFormatter) Format

func (f *JsonFormatter) Format(e *Entry) error

type Level

type Level uint8

Level of log

const (
	DebugLevel Level = iota

	InfoLevel

	WarnLevel

	ErrorLevel

	PanicLevel

	FatalLevel
)

type Option

type Option func(*options)

func WithDisableCaller

func WithDisableCaller(caller bool) Option

func WithFormatter

func WithFormatter(formatter Formatter) Option

func WithLevel

func WithLevel(level Level) Option

func WithOutput

func WithOutput(output io.Writer) Option

func WithStdLevel

func WithStdLevel(level Level) Option

type TextFormatter

type TextFormatter struct {
	IgnoreBasicFields bool
}

func (*TextFormatter) Format

func (f *TextFormatter) Format(e *Entry) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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