log

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 24 Imported by: 20

README

log

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

Install

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

Import

import "github.com/go-spring/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 added in v1.1.1

func RefreshBuffer(buffer string, ext string) error

RefreshBuffer 加载日志配置文件。

func RefreshReader added in v1.1.1

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 added in v1.1.3

type AcceptAllFilter struct{}

AcceptAllFilter causes all logging events to be accepted.

func (*AcceptAllFilter) Filter added in v1.1.3

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 added in v1.1.1

type ArrayValue []Value

ArrayValue represents a slice of Value carried by Field.

func (ArrayValue) Encode added in v1.1.1

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 added in v1.1.1

type BoolValue bool

BoolValue represents a bool carried by Field.

func (BoolValue) Encode added in v1.1.1

func (v BoolValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type BoolsValue added in v1.1.1

type BoolsValue []bool

BoolsValue represents a slice of bool carried by Field.

func (BoolsValue) Encode added in v1.1.1

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 added in v1.1.1

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 added in v1.1.3

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

Debug outputs log with level DebugLevel.

func (*Entry) Debugf added in v1.1.3

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

Debugf outputs log with level DebugLevel.

func (*Entry) Debugw added in v1.1.3

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

Debugw outputs log with level DebugLevel.

func (*Entry) Error added in v1.1.3

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

Error outputs log with level ErrorLevel.

func (*Entry) Errorf added in v1.1.3

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

Errorf outputs log with level ErrorLevel.

func (*Entry) Errorw added in v1.1.3

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

Errorw outputs log with level ErrorLevel.

func (*Entry) Fatal added in v1.1.3

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

Fatal outputs log with level FatalLevel.

func (*Entry) Fatalf added in v1.1.3

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

Fatalf outputs log with level FatalLevel.

func (*Entry) Fatalw added in v1.1.3

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

Fatalw outputs log with level FatalLevel.

func (*Entry) Info added in v1.1.3

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

Info outputs log with level InfoLevel.

func (*Entry) Infof added in v1.1.3

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

Infof outputs log with level InfoLevel.

func (*Entry) Infow added in v1.1.3

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

Infow outputs log with level InfoLevel.

func (*Entry) Panic added in v1.1.3

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

Panic outputs log with level PanicLevel.

func (*Entry) Panicf added in v1.1.3

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

Panicf outputs log with level PanicLevel.

func (*Entry) Panicw added in v1.1.3

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

Panicw outputs log with level PanicLevel.

func (*Entry) Trace added in v1.1.3

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

Trace outputs log with level TraceLevel.

func (*Entry) Tracef added in v1.1.3

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

Tracef outputs log with level TraceLevel.

func (*Entry) Tracew added in v1.1.3

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

Tracew outputs log with level TraceLevel.

func (*Entry) Warn added in v1.1.3

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

Warn outputs log with level WarnLevel.

func (*Entry) Warnf added in v1.1.3

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

Warnf outputs log with level WarnLevel.

func (*Entry) Warnw added in v1.1.3

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

Warnw outputs log with level WarnLevel.

func (*Entry) WithContext added in v1.1.3

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

func (*Entry) WithSkip added in v1.1.3

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

func (*Entry) WithTag added in v1.1.3

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 added in v1.1.1

type Field struct {
	Key string
	Val Value
}

Field is used to replace printf operation with lower cost.

func Any added in v1.1.1

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 added in v1.1.1

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

Array constructs a field that carries a slice of Value.

func Bool added in v1.1.1

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func BoolPtr added in v1.1.3

func BoolPtr(key string, val *bool) Field

BoolPtr constructs a field that carries a *bool.

func Bools added in v1.1.1

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

Bools constructs a field that carries a slice of bool.

func Float32 added in v1.1.1

func Float32(key string, val float32) Field

Float32 constructs a field that carries a float32.

func Float32Ptr added in v1.1.3

func Float32Ptr(key string, val *float32) Field

Float32Ptr constructs a field that carries a *float32.

func Float32s added in v1.1.1

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

Float32s constructs a field that carries a slice of float32.

func Float64 added in v1.1.1

func Float64(key string, val float64) Field

Float64 constructs a field that carries a float64.

func Float64Ptr added in v1.1.3

func Float64Ptr(key string, val *float64) Field

Float64Ptr constructs a field that carries a *float64.

func Float64s added in v1.1.1

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

Float64s constructs a field that carries a slice of float64.

func Int added in v1.1.1

func Int(key string, val int) Field

Int constructs a field that carries an int.

func Int16 added in v1.1.1

func Int16(key string, val int16) Field

Int16 constructs a field that carries an int16.

func Int16Ptr added in v1.1.3

func Int16Ptr(key string, val *int16) Field

Int16Ptr constructs a field that carries a *int16.

func Int16s added in v1.1.1

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

Int16s constructs a field that carries a slice of int16.

func Int32 added in v1.1.1

func Int32(key string, val int32) Field

Int32 constructs a field that carries an int32.

func Int32Ptr added in v1.1.3

func Int32Ptr(key string, val *int32) Field

Int32Ptr constructs a field that carries a *int32.

func Int32s added in v1.1.1

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

Int32s constructs a field that carries a slice of int32.

func Int64 added in v1.1.1

func Int64(key string, val int64) Field

Int64 constructs a field that carries an int64.

func Int64Ptr added in v1.1.3

func Int64Ptr(key string, val *int64) Field

Int64Ptr constructs a field that carries a *int64.

func Int64s added in v1.1.1

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

Int64s constructs a field that carries a slice of int64.

func Int8 added in v1.1.1

func Int8(key string, val int8) Field

Int8 constructs a field that carries an int8.

func Int8Ptr added in v1.1.3

func Int8Ptr(key string, val *int8) Field

Int8Ptr constructs a field that carries a *int8.

func Int8s added in v1.1.1

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

Int8s constructs a field that carries a slice of int8.

func IntPtr added in v1.1.3

func IntPtr(key string, val *int) Field

IntPtr constructs a field that carries a *int.

func Ints added in v1.1.1

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

Ints constructs a field that carries a slice of int.

func Nil added in v1.1.3

func Nil(key string) Field

Nil constructs a field that carries a nil.

func Object added in v1.1.1

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

Object constructs a field that carries a slice of Field.

func Reflect added in v1.1.1

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

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

func String added in v1.1.1

func String(key string, val string) Field

String constructs a field that carries a string.

func StringPtr added in v1.1.3

func StringPtr(key string, val *string) Field

StringPtr constructs a field that carries a *string.

func Strings added in v1.1.1

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

Strings constructs a field that carries a slice of string.

func Uint added in v1.1.1

func Uint(key string, val uint) Field

Uint constructs a field that carries an uint.

func Uint16 added in v1.1.1

func Uint16(key string, val uint16) Field

Uint16 constructs a field that carries an uint16.

func Uint16Ptr added in v1.1.3

func Uint16Ptr(key string, val *uint16) Field

Uint16Ptr constructs a field that carries a *uint16.

func Uint16s added in v1.1.1

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

Uint16s constructs a field that carries a slice of uint16.

func Uint32 added in v1.1.1

func Uint32(key string, val uint32) Field

Uint32 constructs a field that carries an uint32.

func Uint32Ptr added in v1.1.3

func Uint32Ptr(key string, val *uint32) Field

Uint32Ptr constructs a field that carries a *uint32.

func Uint32s added in v1.1.1

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

Uint32s constructs a field that carries a slice of uint32.

func Uint64 added in v1.1.1

func Uint64(key string, val uint64) Field

Uint64 constructs a field that carries an uint64.

func Uint64Ptr added in v1.1.3

func Uint64Ptr(key string, val *uint64) Field

Uint64Ptr constructs a field that carries a *uint64.

func Uint64s added in v1.1.1

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

Uint64s constructs a field that carries a slice of uint64.

func Uint8 added in v1.1.1

func Uint8(key string, val uint8) Field

Uint8 constructs a field that carries an uint8.

func Uint8Ptr added in v1.1.3

func Uint8Ptr(key string, val *uint8) Field

Uint8Ptr constructs a field that carries a *uint8.

func Uint8s added in v1.1.1

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

Uint8s constructs a field that carries a slice of uint8.

func UintPtr added in v1.1.3

func UintPtr(key string, val *uint) Field

UintPtr constructs a field that carries a *uint.

func Uints added in v1.1.1

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

Uints constructs a field that carries a slice of uint.

func W added in v1.1.3

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 added in v1.1.3

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

FlatEncoder encodes Fields in flat format.

func NewFlatEncoder added in v1.1.1

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

NewFlatEncoder return a new *FlatEncoder with separator.

func (*FlatEncoder) AppendArrayBegin added in v1.1.3

func (enc *FlatEncoder) AppendArrayBegin() error

AppendArrayBegin appends an array begin character.

func (*FlatEncoder) AppendArrayEnd added in v1.1.3

func (enc *FlatEncoder) AppendArrayEnd() error

AppendArrayEnd appends an array end character.

func (*FlatEncoder) AppendBool added in v1.1.3

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

AppendBool appends a bool.

func (*FlatEncoder) AppendEncoderBegin added in v1.1.3

func (enc *FlatEncoder) AppendEncoderBegin() error

AppendEncoderBegin appends an encoder begin character.

func (*FlatEncoder) AppendEncoderEnd added in v1.1.3

func (enc *FlatEncoder) AppendEncoderEnd() error

AppendEncoderEnd appends an encoder end character.

func (*FlatEncoder) AppendFloat64 added in v1.1.3

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

AppendFloat64 appends a float64.

func (*FlatEncoder) AppendInt64 added in v1.1.3

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

AppendInt64 appends a int64.

func (*FlatEncoder) AppendKey added in v1.1.3

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

AppendKey appends a key.

func (*FlatEncoder) AppendObjectBegin added in v1.1.3

func (enc *FlatEncoder) AppendObjectBegin() error

AppendObjectBegin appends a object begin character.

func (*FlatEncoder) AppendObjectEnd added in v1.1.3

func (enc *FlatEncoder) AppendObjectEnd() error

AppendObjectEnd appends an object end character.

func (*FlatEncoder) AppendReflect added in v1.1.3

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

AppendReflect appends an interface{}.

func (*FlatEncoder) AppendString added in v1.1.3

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

AppendString appends a string.

func (*FlatEncoder) AppendUint64 added in v1.1.3

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

AppendUint64 appends a uint64.

type Float32sValue added in v1.1.1

type Float32sValue []float32

Float32sValue represents a slice of float32 carried by Field.

func (Float32sValue) Encode added in v1.1.1

func (v Float32sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Float64Value added in v1.1.1

type Float64Value float64

Float64Value represents a float64 carried by Field.

func (Float64Value) Encode added in v1.1.1

func (v Float64Value) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Float64sValue added in v1.1.1

type Float64sValue []float64

Float64sValue represents a slice of float64 carried by Field.

func (Float64sValue) Encode added in v1.1.1

func (v Float64sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type FormatFunc added in v1.1.1

type FormatFunc func(e *Event) string

type Initializer

type Initializer interface {
	Init() error
}

type Int16sValue added in v1.1.1

type Int16sValue []int16

Int16sValue represents a slice of int16 carried by Field.

func (Int16sValue) Encode added in v1.1.1

func (v Int16sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int32sValue added in v1.1.1

type Int32sValue []int32

Int32sValue represents a slice of int32 carried by Field.

func (Int32sValue) Encode added in v1.1.1

func (v Int32sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int64Value added in v1.1.1

type Int64Value int64

Int64Value represents a int64 carried by Field.

func (Int64Value) Encode added in v1.1.1

func (v Int64Value) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int64sValue added in v1.1.1

type Int64sValue []int64

Int64sValue represents a slice of int64 carried by Field.

func (Int64sValue) Encode added in v1.1.1

func (v Int64sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Int8sValue added in v1.1.1

type Int8sValue []int8

Int8sValue represents a slice of int8 carried by Field.

func (Int8sValue) Encode added in v1.1.1

func (v Int8sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type IntsValue added in v1.1.1

type IntsValue []int

IntsValue represents a slice of int carried by Field.

func (IntsValue) Encode added in v1.1.1

func (v IntsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type JSONEncoder added in v1.1.3

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

JSONEncoder encodes Fields in json format.

func NewJSONEncoder added in v1.1.1

func NewJSONEncoder(buf *bytes.Buffer) *JSONEncoder

NewJSONEncoder returns a new *JSONEncoder.

func (*JSONEncoder) AppendArrayBegin added in v1.1.3

func (enc *JSONEncoder) AppendArrayBegin() error

AppendArrayBegin appends an array begin character.

func (*JSONEncoder) AppendArrayEnd added in v1.1.3

func (enc *JSONEncoder) AppendArrayEnd() error

AppendArrayEnd appends an array end character.

func (*JSONEncoder) AppendBool added in v1.1.3

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

AppendBool appends a bool.

func (*JSONEncoder) AppendEncoderBegin added in v1.1.3

func (enc *JSONEncoder) AppendEncoderBegin() error

AppendEncoderBegin appends an encoder begin character.

func (*JSONEncoder) AppendEncoderEnd added in v1.1.3

func (enc *JSONEncoder) AppendEncoderEnd() error

AppendEncoderEnd appends an encoder end character.

func (*JSONEncoder) AppendFloat64 added in v1.1.3

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

AppendFloat64 appends a float64.

func (*JSONEncoder) AppendInt64 added in v1.1.3

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

AppendInt64 appends an int64.

func (*JSONEncoder) AppendKey added in v1.1.3

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

AppendKey appends a key.

func (*JSONEncoder) AppendObjectBegin added in v1.1.3

func (enc *JSONEncoder) AppendObjectBegin() error

AppendObjectBegin appends a object begin character.

func (*JSONEncoder) AppendObjectEnd added in v1.1.3

func (enc *JSONEncoder) AppendObjectEnd() error

AppendObjectEnd appends an object end character.

func (*JSONEncoder) AppendReflect added in v1.1.3

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

AppendReflect appends an interface{}.

func (*JSONEncoder) AppendString added in v1.1.3

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

AppendString appends a string.

func (*JSONEncoder) AppendUint64 added in v1.1.3

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

AppendUint64 appends a uint64.

func (*JSONEncoder) Reset added in v1.1.3

func (enc *JSONEncoder) Reset()

Reset resets the *JSONEncoder.

type JSONLayout added in v1.1.1

type JSONLayout struct{}

A JSONLayout is a layout configurable with JSON encoding.

func (*JSONLayout) ToBytes added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

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 added in v1.1.1

func (c *NullAppender) GetLayout() Layout

func (*NullAppender) GetName added in v1.1.1

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 added in v1.1.1

type ObjectValue []Field

ObjectValue represents a slice of Field carried by Field.

func (ObjectValue) Encode added in v1.1.1

func (v ObjectValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Operator added in v1.1.3

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

func ParseOperator added in v1.1.3

func ParseOperator(s string) (Operator, error)

type PatternLayout added in v1.1.3

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 added in v1.1.3

func (c *PatternLayout) Init() error

func (*PatternLayout) ToBytes added in v1.1.3

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 added in v1.1.1

type ReflectValue struct {
	Val interface{}
}

ReflectValue represents an interface{} carried by Field.

func (ReflectValue) Encode added in v1.1.1

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 added in v1.1.1

type StringValue string

StringValue represents a string carried by Field.

func (StringValue) Encode added in v1.1.1

func (v StringValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type StringsValue added in v1.1.1

type StringsValue []string

StringsValue represents a slice of string carried by Field.

func (StringsValue) Encode added in v1.1.1

func (v StringsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type T added in v1.1.3

type T = func() []interface{}

type TagFilter added in v1.1.1

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 added in v1.1.1

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

func (*TagFilter) Init added in v1.1.1

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 added in v1.1.1

type Uint16sValue []uint16

Uint16sValue represents a slice of uint16 carried by Field.

func (Uint16sValue) Encode added in v1.1.1

func (v Uint16sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint32sValue added in v1.1.1

type Uint32sValue []uint32

Uint32sValue represents a slice of uint32 carried by Field.

func (Uint32sValue) Encode added in v1.1.1

func (v Uint32sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint64Value added in v1.1.1

type Uint64Value uint64

Uint64Value represents a uint64 carried by Field.

func (Uint64Value) Encode added in v1.1.1

func (v Uint64Value) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint64sValue added in v1.1.1

type Uint64sValue []uint64

Uint64sValue represents a slice of uint64 carried by Field.

func (Uint64sValue) Encode added in v1.1.1

func (v Uint64sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Uint8sValue added in v1.1.1

type Uint8sValue []uint8

Uint8sValue represents a slice of uint8 carried by Field.

func (Uint8sValue) Encode added in v1.1.1

func (v Uint8sValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type UintsValue added in v1.1.1

type UintsValue []uint

UintsValue represents a slice of uint carried by Field.

func (UintsValue) Encode added in v1.1.1

func (v UintsValue) Encode(enc Encoder) error

Encode encodes the data represented by v to an Encoder.

type Value added in v1.1.1

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