log

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: Apache-2.0 Imports: 24 Imported by: 9

README

log

重新定义标准日志接口,可以灵活适配各种日志框架。

Install

go get gitee.com/go-spring2/spring-base@v1.1.0-rc2 

Import

import "gitee.com/go-spring2/spring-base/log"

Example

log.SetLevel(log.TraceLevel)
defer log.Reset()

log.Trace("a", "=", "1")
log.Tracef("a=%d", 1)

log.Trace(func() []interface{} {
    return log.T("a", "=", "1")
})

log.Tracef("a=%d", func() []interface{} {
    return log.T(1)
})

...
ctx := context.WithValue(context.TODO(), traceIDKey, "0689")

log.SetLevel(log.TraceLevel)
log.SetOutput(myOutput)
defer log.Reset()

logger := log.Ctx(ctx)
logger.Trace("level:", "trace")
logger.Tracef("level:%s", "trace")

...

logger = log.Tag("__in")
logger.Ctx(ctx).Trace("level:", "trace")
logger.Ctx(ctx).Tracef("level:%s", "trace")

...

Documentation

Index

Constants

View Source
const (
	NoneLevel = Level(iota)
	TraceLevel
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	PanicLevel
	FatalLevel
	OffLevel
)
View Source
const (
	PluginTypeAppender = "Appender"
	PluginTypeFilter   = "Filter"
	PluginTypeLayout   = "Layout"
)
View Source
const (
	ResultAccept = Result(iota)
	ResultDeny
)
View Source
const (
	ColorStyleNone = ColorStyle(iota)
	ColorStyleNormal
	ColorStyleBright
)

Variables

View Source
var Writers = &writers{
	writers: make(map[string]*sharedWriter),
}

Writers manages the Get and Release of Writer(s).

Functions

func Refresh

func Refresh(fileName string) error

Refresh 加载日志配置文件。

func RefreshBuffer

func RefreshBuffer(buffer string, ext string) error

RefreshBuffer 加载日志配置文件。

func RefreshReader

func RefreshReader(input io.Reader, ext string) error

RefreshReader 加载日志配置文件。

func RegisterConverter

func RegisterConverter(fn util.Converter)

RegisterConverter registers Converter for non-primitive type such as time.Time, time.Duration, or other user-defined value type.

func RegisterPlugin

func RegisterPlugin(name string, typ string, i interface{})

RegisterPlugin registers a Plugin, `i` is used to obtain the type of Plugin.

func RegisterReader

func RegisterReader(r Reader, ext ...string)

RegisterReader 注册配置项解析器。

Types

type AcceptAllFilter

type AcceptAllFilter struct{}

AcceptAllFilter causes all logging events to be accepted.

func (*AcceptAllFilter) Filter

func (f *AcceptAllFilter) Filter(e *Event) Result

type Appender

type Appender interface {
	LifeCycle
	GetName() string
	GetLayout() Layout
	Append(e *Event)
}

Appender represents an output destination. Don't provide an asynchronous appender, because we have asynchronous logger.

type AppenderRef

type AppenderRef struct {
	Ref    string `PluginAttribute:"ref"`
	Filter Filter `PluginElement:"Filter"`
	Level  Level  `PluginAttribute:"level,default=none"`
	// contains filtered or unexported fields
}

AppenderRef is a reference to an Appender.

func (*AppenderRef) Append

func (r *AppenderRef) Append(e *Event)

type ArrayValue

type ArrayValue []Value

ArrayValue represents a slice of Value carried by Field.

func (ArrayValue) Encode

func (v ArrayValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type BaseAppender

type BaseAppender struct {
	Name   string `PluginAttribute:"name"`
	Layout Layout `PluginElement:"Layout,default=PatternLayout"`
}

func (*BaseAppender) GetLayout

func (c *BaseAppender) GetLayout() Layout

func (*BaseAppender) GetName

func (c *BaseAppender) GetName() string

func (*BaseAppender) Start

func (c *BaseAppender) Start() error

func (*BaseAppender) Stop

func (c *BaseAppender) Stop(ctx context.Context)

type BoolValue

type BoolValue bool

BoolValue represents a bool carried by Field.

func (BoolValue) Encode

func (v BoolValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type BoolsValue

type BoolsValue []bool

BoolsValue represents a slice of bool carried by Field.

func (BoolsValue) Encode

func (v BoolsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type ColorStyle

type ColorStyle int

func ParseColorStyle

func ParseColorStyle(s string) (ColorStyle, error)

ParseColorStyle parses `s` to a ColorStyle value.

type CompositeFilter

type CompositeFilter struct {
	Filters  []Filter `PluginElement:"Filter"`
	Operator Operator //`PluginAttribute:"operator,default=and"`
}

func (*CompositeFilter) Filter

func (f *CompositeFilter) Filter(e *Event) Result

func (*CompositeFilter) Start

func (f *CompositeFilter) Start() error

func (*CompositeFilter) Stop

func (f *CompositeFilter) Stop(ctx context.Context)

type ConsoleAppender

type ConsoleAppender struct {
	BaseAppender
}

ConsoleAppender is an Appender that writing messages to os.Stdout.

func (*ConsoleAppender) Append

func (c *ConsoleAppender) Append(e *Event)

type DenyAllFilter

type DenyAllFilter struct{}

DenyAllFilter causes all logging events to be dropped.

func (*DenyAllFilter) Filter

func (f *DenyAllFilter) Filter(e *Event) Result

type Encoder

type Encoder interface {
	AppendEncoderBegin() error
	AppendEncoderEnd() error
	AppendObjectBegin() error
	AppendObjectEnd() error
	AppendArrayBegin() error
	AppendArrayEnd() error
	AppendKey(key string) error
	AppendBool(v bool) error
	AppendInt64(v int64) error
	AppendUint64(v uint64) error
	AppendFloat64(v float64) error
	AppendString(v string) error
	AppendReflect(v interface{}) error
}

An Encoder is used to serialize strongly-typed Field.

type Entry

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

Entry is an Entry implementation that has context and errno.

func (*Entry) Debug

func (e *Entry) Debug(args ...interface{}) *Event

Debug outputs log with level DebugLevel.

func (*Entry) Debugf

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

Debugf outputs log with level DebugLevel.

func (*Entry) Debugw

func (e *Entry) Debugw(fields ...Field) *Event

Debugw outputs log with level DebugLevel.

func (*Entry) Error

func (e *Entry) Error(args ...interface{}) *Event

Error outputs log with level ErrorLevel.

func (*Entry) Errorf

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

Errorf outputs log with level ErrorLevel.

func (*Entry) Errorw

func (e *Entry) Errorw(fields ...Field) *Event

Errorw outputs log with level ErrorLevel.

func (*Entry) Fatal

func (e *Entry) Fatal(args ...interface{}) *Event

Fatal outputs log with level FatalLevel.

func (*Entry) Fatalf

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

Fatalf outputs log with level FatalLevel.

func (*Entry) Fatalw

func (e *Entry) Fatalw(fields ...Field) *Event

Fatalw outputs log with level FatalLevel.

func (*Entry) Info

func (e *Entry) Info(args ...interface{}) *Event

Info outputs log with level InfoLevel.

func (*Entry) Infof

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

Infof outputs log with level InfoLevel.

func (*Entry) Infow

func (e *Entry) Infow(fields ...Field) *Event

Infow outputs log with level InfoLevel.

func (*Entry) Panic

func (e *Entry) Panic(args ...interface{}) *Event

Panic outputs log with level PanicLevel.

func (*Entry) Panicf

func (e *Entry) Panicf(format string, args ...interface{}) *Event

Panicf outputs log with level PanicLevel.

func (*Entry) Panicw

func (e *Entry) Panicw(fields ...Field) *Event

Panicw outputs log with level PanicLevel.

func (*Entry) Trace

func (e *Entry) Trace(args ...interface{}) *Event

Trace outputs log with level TraceLevel.

func (*Entry) Tracef

func (e *Entry) Tracef(format string, args ...interface{}) *Event

Tracef outputs log with level TraceLevel.

func (*Entry) Tracew

func (e *Entry) Tracew(fields ...Field) *Event

Tracew outputs log with level TraceLevel.

func (*Entry) Warn

func (e *Entry) Warn(args ...interface{}) *Event

Warn outputs log with level WarnLevel.

func (*Entry) Warnf

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

Warnf outputs log with level WarnLevel.

func (*Entry) Warnw

func (e *Entry) Warnw(fields ...Field) *Event

Warnw outputs log with level WarnLevel.

func (*Entry) WithContext

func (e *Entry) WithContext(ctx context.Context) *Entry

func (*Entry) WithSkip

func (e *Entry) WithSkip(n int) *Entry

func (*Entry) WithTag

func (e *Entry) WithTag(tag string) *Entry

type Event

type Event struct {
	Context context.Context
	Level   Level
	Time    time.Time
	File    string
	Line    int
	Tag     string
	Fields  []Field
	Message string
}

Event provides contextual information about a log message.

type Field

type Field struct {
	Key string
	Val Value
}

Field is used to replace printf operation with lower cost.

func Any

func Any(key string, value interface{}) Field

Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.

func Array

func Array(key string, val ...Value) Field

Array constructs a field that carries a slice of Value.

func Bool

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func BoolPtr

func BoolPtr(key string, val *bool) Field

BoolPtr constructs a field that carries a *bool.

func Bools

func Bools(key string, val []bool) Field

Bools constructs a field that carries a slice of bool.

func Float32

func Float32(key string, val float32) Field

Float32 constructs a field that carries a float32.

func Float32Ptr

func Float32Ptr(key string, val *float32) Field

Float32Ptr constructs a field that carries a *float32.

func Float32s

func Float32s(key string, val []float32) Field

Float32s constructs a field that carries a slice of float32.

func Float64

func Float64(key string, val float64) Field

Float64 constructs a field that carries a float64.

func Float64Ptr

func Float64Ptr(key string, val *float64) Field

Float64Ptr constructs a field that carries a *float64.

func Float64s

func Float64s(key string, val []float64) Field

Float64s constructs a field that carries a slice of float64.

func Int

func Int(key string, val int) Field

Int constructs a field that carries an int.

func Int16

func Int16(key string, val int16) Field

Int16 constructs a field that carries an int16.

func Int16Ptr

func Int16Ptr(key string, val *int16) Field

Int16Ptr constructs a field that carries a *int16.

func Int16s

func Int16s(key string, val []int16) Field

Int16s constructs a field that carries a slice of int16.

func Int32

func Int32(key string, val int32) Field

Int32 constructs a field that carries an int32.

func Int32Ptr

func Int32Ptr(key string, val *int32) Field

Int32Ptr constructs a field that carries a *int32.

func Int32s

func Int32s(key string, val []int32) Field

Int32s constructs a field that carries a slice of int32.

func Int64

func Int64(key string, val int64) Field

Int64 constructs a field that carries an int64.

func Int64Ptr

func Int64Ptr(key string, val *int64) Field

Int64Ptr constructs a field that carries a *int64.

func Int64s

func Int64s(key string, val []int64) Field

Int64s constructs a field that carries a slice of int64.

func Int8

func Int8(key string, val int8) Field

Int8 constructs a field that carries an int8.

func Int8Ptr

func Int8Ptr(key string, val *int8) Field

Int8Ptr constructs a field that carries a *int8.

func Int8s

func Int8s(key string, val []int8) Field

Int8s constructs a field that carries a slice of int8.

func IntPtr

func IntPtr(key string, val *int) Field

IntPtr constructs a field that carries a *int.

func Ints

func Ints(key string, val []int) Field

Ints constructs a field that carries a slice of int.

func Nil

func Nil(key string) Field

Nil constructs a field that carries a nil.

func Object

func Object(key string, fields ...Field) Field

Object constructs a field that carries a slice of Field.

func Reflect

func Reflect(key string, val interface{}) Field

Reflect constructs a field that carries an interface{}, which should be serialized using reflection.

func String

func String(key string, val string) Field

String constructs a field that carries a string.

func StringPtr

func StringPtr(key string, val *string) Field

StringPtr constructs a field that carries a *string.

func Strings

func Strings(key string, val []string) Field

Strings constructs a field that carries a slice of string.

func Uint

func Uint(key string, val uint) Field

Uint constructs a field that carries an uint.

func Uint16

func Uint16(key string, val uint16) Field

Uint16 constructs a field that carries an uint16.

func Uint16Ptr

func Uint16Ptr(key string, val *uint16) Field

Uint16Ptr constructs a field that carries a *uint16.

func Uint16s

func Uint16s(key string, val []uint16) Field

Uint16s constructs a field that carries a slice of uint16.

func Uint32

func Uint32(key string, val uint32) Field

Uint32 constructs a field that carries an uint32.

func Uint32Ptr

func Uint32Ptr(key string, val *uint32) Field

Uint32Ptr constructs a field that carries a *uint32.

func Uint32s

func Uint32s(key string, val []uint32) Field

Uint32s constructs a field that carries a slice of uint32.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 constructs a field that carries an uint64.

func Uint64Ptr

func Uint64Ptr(key string, val *uint64) Field

Uint64Ptr constructs a field that carries a *uint64.

func Uint64s

func Uint64s(key string, val []uint64) Field

Uint64s constructs a field that carries a slice of uint64.

func Uint8

func Uint8(key string, val uint8) Field

Uint8 constructs a field that carries an uint8.

func Uint8Ptr

func Uint8Ptr(key string, val *uint8) Field

Uint8Ptr constructs a field that carries a *uint8.

func Uint8s

func Uint8s(key string, val []uint8) Field

Uint8s constructs a field that carries a slice of uint8.

func UintPtr

func UintPtr(key string, val *uint) Field

UintPtr constructs a field that carries a *uint.

func Uints

func Uints(key string, val []uint) Field

Uints constructs a field that carries a slice of uint.

func W

func W(fn func() []Field) Field

type FileAppender

type FileAppender struct {
	BaseAppender

	FileName string `PluginAttribute:"fileName"`
	// contains filtered or unexported fields
}

FileAppender is an Appender writing messages to *os.File.

func (*FileAppender) Append

func (c *FileAppender) Append(e *Event)

func (*FileAppender) Start

func (c *FileAppender) Start() error

func (*FileAppender) Stop

func (c *FileAppender) Stop(ctx context.Context)

type FileWriter

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

FileWriter is a Writer implementation by *os.File.

func (*FileWriter) Name

func (c *FileWriter) Name() string

func (*FileWriter) Stop

func (c *FileWriter) Stop(ctx context.Context)

func (*FileWriter) Write

func (c *FileWriter) Write(p []byte) (n int, err error)

type Filter

type Filter interface {
	Filter(e *Event) Result
}

Filter is an interface that tells the logger a log message should be dropped when the Filter method returns ResultDeny. Filter 只应该出现在两个地方,一个是 Logger 上,用于控制消息是否打印,另一个是 AppenderRef,用于控制消息是否输出到 Appender 上,即控制消息路由。

type FlatEncoder

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

FlatEncoder encodes Fields in flat format.

func NewFlatEncoder

func NewFlatEncoder(buf *bytes.Buffer, separator string) *FlatEncoder

NewFlatEncoder return a new *FlatEncoder with separator.

func (*FlatEncoder) AppendArrayBegin

func (enc *FlatEncoder) AppendArrayBegin() error

AppendArrayBegin appends an array begin character.

func (*FlatEncoder) AppendArrayEnd

func (enc *FlatEncoder) AppendArrayEnd() error

AppendArrayEnd appends an array end character.

func (*FlatEncoder) AppendBool

func (enc *FlatEncoder) AppendBool(v bool) error

AppendBool appends a bool.

func (*FlatEncoder) AppendEncoderBegin

func (enc *FlatEncoder) AppendEncoderBegin() error

AppendEncoderBegin appends an encoder begin character.

func (*FlatEncoder) AppendEncoderEnd

func (enc *FlatEncoder) AppendEncoderEnd() error

AppendEncoderEnd appends an encoder end character.

func (*FlatEncoder) AppendFloat64

func (enc *FlatEncoder) AppendFloat64(v float64) error

AppendFloat64 appends a float64.

func (*FlatEncoder) AppendInt64

func (enc *FlatEncoder) AppendInt64(v int64) error

AppendInt64 appends a int64.

func (*FlatEncoder) AppendKey

func (enc *FlatEncoder) AppendKey(key string) error

AppendKey appends a key.

func (*FlatEncoder) AppendObjectBegin

func (enc *FlatEncoder) AppendObjectBegin() error

AppendObjectBegin appends a object begin character.

func (*FlatEncoder) AppendObjectEnd

func (enc *FlatEncoder) AppendObjectEnd() error

AppendObjectEnd appends an object end character.

func (*FlatEncoder) AppendReflect

func (enc *FlatEncoder) AppendReflect(v interface{}) error

AppendReflect appends an interface{}.

func (*FlatEncoder) AppendString

func (enc *FlatEncoder) AppendString(v string) error

AppendString appends a string.

func (*FlatEncoder) AppendUint64

func (enc *FlatEncoder) AppendUint64(v uint64) error

AppendUint64 appends a uint64.

type Float32sValue

type Float32sValue []float32

Float32sValue represents a slice of float32 carried by Field.

func (Float32sValue) Encode

func (v Float32sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Float64Value

type Float64Value float64

Float64Value represents a float64 carried by Field.

func (Float64Value) Encode

func (v Float64Value) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Float64sValue

type Float64sValue []float64

Float64sValue represents a slice of float64 carried by Field.

func (Float64sValue) Encode

func (v Float64sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type FormatFunc

type FormatFunc func(e *Event) string

type Initializer

type Initializer interface {
	Init() error
}

type Int16sValue

type Int16sValue []int16

Int16sValue represents a slice of int16 carried by Field.

func (Int16sValue) Encode

func (v Int16sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int32sValue

type Int32sValue []int32

Int32sValue represents a slice of int32 carried by Field.

func (Int32sValue) Encode

func (v Int32sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int64Value

type Int64Value int64

Int64Value represents a int64 carried by Field.

func (Int64Value) Encode

func (v Int64Value) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int64sValue

type Int64sValue []int64

Int64sValue represents a slice of int64 carried by Field.

func (Int64sValue) Encode

func (v Int64sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int8sValue

type Int8sValue []int8

Int8sValue represents a slice of int8 carried by Field.

func (Int8sValue) Encode

func (v Int8sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type IntsValue

type IntsValue []int

IntsValue represents a slice of int carried by Field.

func (IntsValue) Encode

func (v IntsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type JSONEncoder

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

JSONEncoder encodes Fields in json format.

func NewJSONEncoder

func NewJSONEncoder(buf *bytes.Buffer) *JSONEncoder

NewJSONEncoder returns a new *JSONEncoder.

func (*JSONEncoder) AppendArrayBegin

func (enc *JSONEncoder) AppendArrayBegin() error

AppendArrayBegin appends an array begin character.

func (*JSONEncoder) AppendArrayEnd

func (enc *JSONEncoder) AppendArrayEnd() error

AppendArrayEnd appends an array end character.

func (*JSONEncoder) AppendBool

func (enc *JSONEncoder) AppendBool(v bool) error

AppendBool appends a bool.

func (*JSONEncoder) AppendEncoderBegin

func (enc *JSONEncoder) AppendEncoderBegin() error

AppendEncoderBegin appends an encoder begin character.

func (*JSONEncoder) AppendEncoderEnd

func (enc *JSONEncoder) AppendEncoderEnd() error

AppendEncoderEnd appends an encoder end character.

func (*JSONEncoder) AppendFloat64

func (enc *JSONEncoder) AppendFloat64(v float64) error

AppendFloat64 appends a float64.

func (*JSONEncoder) AppendInt64

func (enc *JSONEncoder) AppendInt64(v int64) error

AppendInt64 appends an int64.

func (*JSONEncoder) AppendKey

func (enc *JSONEncoder) AppendKey(key string) error

AppendKey appends a key.

func (*JSONEncoder) AppendObjectBegin

func (enc *JSONEncoder) AppendObjectBegin() error

AppendObjectBegin appends a object begin character.

func (*JSONEncoder) AppendObjectEnd

func (enc *JSONEncoder) AppendObjectEnd() error

AppendObjectEnd appends an object end character.

func (*JSONEncoder) AppendReflect

func (enc *JSONEncoder) AppendReflect(v interface{}) error

AppendReflect appends an interface{}.

func (*JSONEncoder) AppendString

func (enc *JSONEncoder) AppendString(v string) error

AppendString appends a string.

func (*JSONEncoder) AppendUint64

func (enc *JSONEncoder) AppendUint64(u uint64) error

AppendUint64 appends a uint64.

func (*JSONEncoder) Reset

func (enc *JSONEncoder) Reset()

Reset resets the *JSONEncoder.

type JSONLayout

type JSONLayout struct{}

A JSONLayout is a layout configurable with JSON encoding.

func (*JSONLayout) ToBytes

func (c *JSONLayout) ToBytes(e *Event) ([]byte, error)

ToBytes lays out an Event in []byte format.

type Layout

type Layout interface {
	ToBytes(e *Event) ([]byte, error)
}

Layout lays out an Event in []byte format.

type Level

type Level int32

Level used for identifying the severity of an event.

func ParseLevel

func ParseLevel(str string) (Level, error)

ParseLevel parses string to a level, and returns error if the conversion fails.

func (Level) String

func (level Level) String() string

type LevelFilter

type LevelFilter struct {
	Level Level `PluginAttribute:"level"`
}

LevelFilter logs events if the level in the Event is same or more specific than the configured level.

func (*LevelFilter) Filter

func (f *LevelFilter) Filter(e *Event) Result

type LevelMatchFilter

type LevelMatchFilter struct {
	Level Level `PluginAttribute:"level"`
}

LevelMatchFilter logs events if the level in the Event matches the specified logging level exactly.

func (*LevelMatchFilter) Filter

func (f *LevelMatchFilter) Filter(e *Event) Result

type LevelRangeFilter

type LevelRangeFilter struct {
	Min Level `PluginAttribute:"min"`
	Max Level `PluginAttribute:"max"`
}

LevelRangeFilter logs events if the level in the Event is in the range of the configured min and max levels.

func (*LevelRangeFilter) Filter

func (f *LevelRangeFilter) Filter(e *Event) Result

type LifeCycle

type LifeCycle interface {
	Start() error
	Stop(ctx context.Context)
}

type Logger

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

func GetLogger

func GetLogger(name string) *Logger

func (*Logger) Appenders

func (l *Logger) Appenders() []Appender

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{}) *Event

Debug outputs log with level DebugLevel.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{}) *Event

Debugf outputs log with level DebugLevel.

func (*Logger) Debugw

func (l *Logger) Debugw(fields ...Field) *Event

Debugw outputs log with level DebugLevel.

func (*Logger) Error

func (l *Logger) Error(args ...interface{}) *Event

Error outputs log with level ErrorLevel.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{}) *Event

Errorf outputs log with level ErrorLevel.

func (*Logger) Errorw

func (l *Logger) Errorw(fields ...Field) *Event

Errorw outputs log with level ErrorLevel.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{}) *Event

Fatal outputs log with level FatalLevel.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{}) *Event

Fatalf outputs log with level FatalLevel.

func (*Logger) Fatalw

func (l *Logger) Fatalw(fields ...Field) *Event

Fatalw outputs log with level FatalLevel.

func (*Logger) Info

func (l *Logger) Info(args ...interface{}) *Event

Info outputs log with level InfoLevel.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{}) *Event

Infof outputs log with level InfoLevel.

func (*Logger) Infow

func (l *Logger) Infow(fields ...Field) *Event

Infow outputs log with level InfoLevel.

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) Name

func (l *Logger) Name() string

Name returns the logger's name.

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{}) *Event

Panic outputs log with level PanicLevel.

func (*Logger) Panicf

func (l *Logger) Panicf(format string, args ...interface{}) *Event

Panicf outputs log with level PanicLevel.

func (*Logger) Panicw

func (l *Logger) Panicw(fields ...Field) *Event

Panicw outputs log with level PanicLevel.

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{}) *Event

Trace outputs log with level TraceLevel.

func (*Logger) Tracef

func (l *Logger) Tracef(format string, args ...interface{}) *Event

Tracef outputs log with level TraceLevel.

func (*Logger) Tracew

func (l *Logger) Tracew(fields ...Field) *Event

Tracew outputs log with level TraceLevel.

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{}) *Event

Warn outputs log with level WarnLevel.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{}) *Event

Warnf outputs log with level WarnLevel.

func (*Logger) Warnw

func (l *Logger) Warnw(fields ...Field) *Event

Warnw outputs log with level WarnLevel.

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Entry

WithContext 创建包含 context.Context 对象的 Entry 。

func (*Logger) WithSkip

func (l *Logger) WithSkip(n int) *Entry

WithSkip 创建包含 skip 信息的 Entry 。

func (*Logger) WithTag

func (l *Logger) WithTag(tag string) *Entry

WithTag 创建包含 tag 信息的 Entry 。

type Node

type Node struct {
	Label      string
	Children   []*Node
	Attributes map[string]string
}

type NullAppender

type NullAppender struct{}

NullAppender is an Appender that ignores log events.

func (*NullAppender) Append

func (c *NullAppender) Append(e *Event)

func (*NullAppender) GetLayout

func (c *NullAppender) GetLayout() Layout

func (*NullAppender) GetName

func (c *NullAppender) GetName() string

func (*NullAppender) Start

func (c *NullAppender) Start() error

func (*NullAppender) Stop

func (c *NullAppender) Stop(ctx context.Context)

type ObjectValue

type ObjectValue []Field

ObjectValue represents a slice of Field carried by Field.

func (ObjectValue) Encode

func (v ObjectValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Operator

type Operator int
const (
	OperatorAnd Operator = iota
	OperatorOr
	OperatorNone
)

func ParseOperator

func ParseOperator(s string) (Operator, error)

type PatternLayout

type PatternLayout struct {
	ColorStyle ColorStyle `PluginAttribute:"colorStyle,default=none"`
	Pattern    string     `PluginAttribute:"pattern,default=[:level][:time][:fileline][:msg]"`
	// contains filtered or unexported fields
}

A PatternLayout is a flexible layout configurable with pattern string.

func (*PatternLayout) Init

func (c *PatternLayout) Init() error

func (*PatternLayout) ToBytes

func (c *PatternLayout) ToBytes(e *Event) ([]byte, error)

ToBytes lays out an Event in []byte format.

type Plugin

type Plugin struct {
	Name  string
	Type  string
	Class reflect.Type
	File  string
	Line  int
}

Plugin is the name of node label or XML element.

type PluginTag

type PluginTag string

func (PluginTag) Get

func (tag PluginTag) Get(key string) string

func (PluginTag) Lookup

func (tag PluginTag) Lookup(key string) (value string, ok bool)

type Reader

type Reader interface {
	Read(b []byte) (*Node, error)
}

Reader 配置项解析器。

type ReflectValue

type ReflectValue struct {
	Val interface{}
}

ReflectValue represents an interface{} carried by Field.

func (ReflectValue) Encode

func (v ReflectValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Result

type Result int

type RollingFileAppender

type RollingFileAppender struct {
	BaseAppender
}

func (*RollingFileAppender) Append

func (c *RollingFileAppender) Append(e *Event)

type StringValue

type StringValue string

StringValue represents a string carried by Field.

func (StringValue) Encode

func (v StringValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type StringsValue

type StringsValue []string

StringsValue represents a slice of string carried by Field.

func (StringsValue) Encode

func (v StringsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type T

type T = func() []interface{}

type TagFilter

type TagFilter struct {
	Prefix string `PluginAttribute:"prefix,default="`
	Suffix string `PluginAttribute:"suffix,default="`
	Tag    string `PluginAttribute:"tag,default="`
	// contains filtered or unexported fields
}

func (*TagFilter) Filter

func (f *TagFilter) Filter(e *Event) Result

func (*TagFilter) Init

func (f *TagFilter) Init() error

type TimeFilter

type TimeFilter struct {
	Timezone string `PluginAttribute:"timezone,default=Local"`
	Start    string `PluginAttribute:"start"`
	End      string `PluginAttribute:"end"`
	// contains filtered or unexported fields
}

TimeFilter filters events that fall within a specified time period in each day.

func (*TimeFilter) Filter

func (f *TimeFilter) Filter(e *Event) Result

func (*TimeFilter) Init

func (f *TimeFilter) Init() error

type Uint16sValue

type Uint16sValue []uint16

Uint16sValue represents a slice of uint16 carried by Field.

func (Uint16sValue) Encode

func (v Uint16sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint32sValue

type Uint32sValue []uint32

Uint32sValue represents a slice of uint32 carried by Field.

func (Uint32sValue) Encode

func (v Uint32sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint64Value

type Uint64Value uint64

Uint64Value represents a uint64 carried by Field.

func (Uint64Value) Encode

func (v Uint64Value) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint64sValue

type Uint64sValue []uint64

Uint64sValue represents a slice of uint64 carried by Field.

func (Uint64sValue) Encode

func (v Uint64sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint8sValue

type Uint8sValue []uint8

Uint8sValue represents a slice of uint8 carried by Field.

func (Uint8sValue) Encode

func (v Uint8sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type UintsValue

type UintsValue []uint

UintsValue represents a slice of uint carried by Field.

func (UintsValue) Encode

func (v UintsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Value

type Value interface {
	Encode(enc Encoder) error
}

Value represents a data and encodes it to an Encoder.

type Writer

type Writer interface {
	io.Writer
	Name() string
	Stop(ctx context.Context)
}

Writer is io.Writer with a name and a Stop method.

func NewFileWriter

func NewFileWriter(fileName string) (Writer, error)

NewFileWriter returns a FileWriter that a Writer implementation.

type XMLReader

type XMLReader struct{}

func (*XMLReader) Read

func (r *XMLReader) Read(b []byte) (*Node, error)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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