log

package
v0.0.0-...-273cdd3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeLayout = "2006-01-02 15:04:05.000"
View Source
const Error = "error"
View Source
const Module = "module"

Variables

View Source
var StdWriter = &stdWriter{level: DEBUG, writer: os.Stdout}

Functions

This section is empty.

Types

type Entry

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

日志接口

func (*Entry) Data

func (entry *Entry) Data(key string, value interface{}) Logger

func (*Entry) Debug

func (entry *Entry) Debug(args ...interface{})

func (*Entry) Debugf

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

func (*Entry) Error

func (entry *Entry) Error(args ...interface{})

func (*Entry) Errorf

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

func (*Entry) Fatal

func (entry *Entry) Fatal(args ...interface{})

func (*Entry) Fatalf

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

func (*Entry) Field

func (entry *Entry) Field(key string, value interface{}) Logger

func (*Entry) Fields

func (entry *Entry) Fields(fields context.Fields) Logger

func (*Entry) Info

func (entry *Entry) Info(args ...interface{})

func (*Entry) Infof

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

func (*Entry) Level

func (entry *Entry) Level(level Level) Logger

设置日志等级

func (*Entry) Log

func (entry *Entry) Log(level Level, args ...interface{})

func (*Entry) Logf

func (entry *Entry) Logf(level Level, format string, args ...interface{})

func (*Entry) Warn

func (entry *Entry) Warn(args ...interface{})

func (*Entry) Warnf

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

type Formatter

type Formatter interface {
	Format(*Log) ([]byte, error)
}

type Grade

type Grade string
const (
	GradeDebug Grade = "debug"
	GradeInfo  Grade = "info"
	GradeWarn  Grade = "warn"
	GradeError Grade = "error"
	GradeFatal Grade = "fatal"
)

func (Grade) Level

func (grade Grade) Level() Level

type Hook

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

func NewHook

func NewHook(formatter Formatter) *Hook

func (*Hook) Enable

func (hook *Hook) Enable(level Level) bool

设置日志等级

func (*Hook) Hook

func (hook *Hook) Hook(log *Log)

调用接口

func (*Hook) Writer

func (hook *Hook) Writer(writer Writer) *Hook

设置写入器

type JsonFormatter

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

func Json

func Json() *JsonFormatter

func (*JsonFormatter) Format

func (formatter *JsonFormatter) Format(log *Log) ([]byte, error)

func (*JsonFormatter) TimeLayout

func (formatter *JsonFormatter) TimeLayout(layout string) *JsonFormatter

type JsonLog

type JsonLog struct {
	Level   string          `json:"level"`
	Time    string          `json:"time"`
	Data    json.RawMessage `json:"data,omitempty"`
	Context json.RawMessage `json:"context,omitempty"`
	Message string          `json:"message"`
}

type Level

type Level int8
const (
	DEBUG Level = 1 << iota
	INFO
	WARN
	ERROR
	FATAL
	INVALID
)

func (Level) Enable

func (level Level) Enable(other Level) bool

func (Level) Grade

func (level Level) Grade() Grade

func (Level) Valid

func (level Level) Valid() bool

type Log

type Log struct {
	Level   Level            // 等级
	Time    time.Time        // 事件
	Data    *context.Context // 数据
	Context *context.Context // 上下文
	Message string           // 格式化信息
}

日志信息

type Logger

type Logger interface {
	Level(Level) Logger
	Field(string, interface{}) Logger
	Fields(context.Fields) Logger
	Data(string, interface{}) Logger
	Debug(...interface{})
	Debugf(string, ...interface{})
	Info(...interface{})
	Infof(string, ...interface{})
	Warn(...interface{})
	Warnf(string, ...interface{})
	Error(...interface{})
	Errorf(string, ...interface{})
	Fatal(...interface{})
	Fatalf(string, ...interface{})
}

func NewEntry

func NewEntry(hooks ...*Hook) Logger

创建日志接口

type TextFormatter

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

func Text

func Text() *TextFormatter

func (*TextFormatter) Format

func (formatter *TextFormatter) Format(log *Log) ([]byte, error)

func (*TextFormatter) Level

func (formatter *TextFormatter) Level(level Level) string

func (*TextFormatter) TimeLayout

func (formatter *TextFormatter) TimeLayout(layout string) *TextFormatter

type Writer

type Writer interface {
	Enable(Level) bool
	Write(log *Log, raw []byte)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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