log

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

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 (
	ResultAccept = Result(iota)
	ResultDeny
)
View Source
const (
	ColorStyleNone = ColorStyle(iota)
	ColorStyleNormal
	ColorStyleBright
)
View Source
const (
	NoneLevel = Level(iota)
	TraceLevel
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	PanicLevel
	FatalLevel
	OffLevel
)
View Source
const (
	PluginTypeAppender = "Appender"
	PluginTypeFilter   = "Filter"
	PluginTypeLayout   = "Layout"
)

Variables

View Source
var (

	// Status records events that occur in the logging system.
	Status = newLogger("", ErrorLevel)
)
View Source
var Writers = &writers{
	writers: make(map[string]*sharedWriter),
}

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

Functions

func Caller

func Caller(skip int, fast bool) (file string, line int, loaded bool)

Caller 获取调用点的文件及行号信息,fast 为 true 时使用缓存进行加速。

func NewFlatEncoder added in v1.1.1

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

func NewJSONEncoder added in v1.1.1

func NewJSONEncoder(buf *bytes.Buffer) *jsonEncoder

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 Appender

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

Appender represents an output destination. Do not 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

func (ArrayValue) Encode added in v1.1.1

func (v ArrayValue) Encode(enc Encoder) error

type BaseAppender

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

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 BaseFilter

type BaseFilter struct {
	OnMatch    Result `PluginAttribute:"onMatch,default=accept"`
	OnMismatch Result `PluginAttribute:"onMismatch,default=deny"`
}

func (*BaseFilter) Start

func (c *BaseFilter) Start() error

func (*BaseFilter) Stop

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

type BoolValue added in v1.1.1

type BoolValue bool

func (BoolValue) Encode added in v1.1.1

func (v BoolValue) Encode(enc Encoder) error

type BoolsValue added in v1.1.1

type BoolsValue []bool

func (BoolsValue) Encode added in v1.1.1

func (v BoolsValue) Encode(enc Encoder) error

type ColorStyle

type ColorStyle int

func ParseColorStyle

func ParseColorStyle(s string) (ColorStyle, error)

type CompositeFilter

type CompositeFilter struct {
	Filters []Filter `PluginElement:"Filter"`
}

CompositeFilter composes and invokes one or more filters.

func (*CompositeFilter) Filter

func (f *CompositeFilter) Filter(level Level, e Entry, fields []Field) 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 ContextEntry

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

ContextEntry is an Entry implementation that has context and errno.

func (*ContextEntry) Context

func (e *ContextEntry) Context() context.Context

func (ContextEntry) Debug

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

Debug outputs log with level DebugLevel.

func (ContextEntry) Debugf

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

Debugf outputs log with level DebugLevel.

func (ContextEntry) Debugw added in v1.1.1

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

Debugw outputs log with level DebugLevel.

func (*ContextEntry) Errno

func (e *ContextEntry) Errno() Errno

func (ContextEntry) Error

func (e ContextEntry) Error(errno Errno, args ...interface{}) *Event

Error outputs log with level ErrorLevel.

func (ContextEntry) Errorf

func (e ContextEntry) Errorf(errno Errno, format string, args ...interface{}) *Event

Errorf outputs log with level ErrorLevel.

func (ContextEntry) Errorw added in v1.1.1

func (e ContextEntry) Errorw(errno Errno, fields ...Field) *Event

Errorw outputs log with level ErrorLevel.

func (ContextEntry) Fatal

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

Fatal outputs log with level FatalLevel.

func (ContextEntry) Fatalf

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

Fatalf outputs log with level FatalLevel.

func (ContextEntry) Fatalw added in v1.1.1

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

Fatalw outputs log with level FatalLevel.

func (ContextEntry) Info

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

Info outputs log with level InfoLevel.

func (ContextEntry) Infof

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

Infof outputs log with level InfoLevel.

func (ContextEntry) Infow added in v1.1.1

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

Infow outputs log with level InfoLevel.

func (ContextEntry) Panic

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

Panic outputs log with level PanicLevel.

func (ContextEntry) Panicf

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

Panicf outputs log with level PanicLevel.

func (ContextEntry) Panicw added in v1.1.1

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

Panicw outputs log with level PanicLevel.

func (*ContextEntry) Tag

func (e *ContextEntry) Tag() string

func (ContextEntry) Trace

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

Trace outputs log with level TraceLevel.

func (ContextEntry) Tracef

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

Tracef outputs log with level TraceLevel.

func (ContextEntry) Tracew added in v1.1.1

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

Tracew outputs log with level TraceLevel.

func (ContextEntry) Warn

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

Warn outputs log with level WarnLevel.

func (ContextEntry) Warnf

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

Warnf outputs log with level WarnLevel.

func (ContextEntry) Warnw added in v1.1.1

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

Warnw outputs log with level WarnLevel.

func (ContextEntry) WithSkip

func (e ContextEntry) WithSkip(n int) ContextEntry

func (ContextEntry) WithTag

func (e ContextEntry) WithTag(tag string) ContextEntry

type DefaultLayout

type DefaultLayout struct {
	LineBreak  bool       `PluginAttribute:"lineBreak,default=true"`
	ColorStyle ColorStyle `PluginAttribute:"colorStyle,default=none"`
	Formatter  string     `PluginAttribute:"formatter,default="`
	// contains filtered or unexported fields
}

func (*DefaultLayout) Init added in v1.1.1

func (c *DefaultLayout) Init() error

func (*DefaultLayout) ToBytes

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

type DenyAllFilter

type DenyAllFilter struct{}

DenyAllFilter causes all logging events to be dropped.

func (*DenyAllFilter) Filter

func (f *DenyAllFilter) Filter(_ Level, _ Entry, _ []Field) Result

func (*DenyAllFilter) Start

func (f *DenyAllFilter) Start() error

func (*DenyAllFilter) Stop

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

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(bool) error
	AppendInt64(int64) error
	AppendUint64(uint64) error
	AppendFloat64(float64) error
	AppendString(string) error
	AppendReflect(v interface{}) error
	AppendBuffer([]byte) error
}

type Entry

type Entry interface {
	Tag() string
	Errno() Errno
	Context() context.Context
}

Entry provides context, errno and tag about a log message.

type Errno

type Errno interface {
	Msg() string
	Code() uint32
}
var (
	OK    Errno = &errno{project: 0, code: 0, message: "OK"}
	ERROR Errno = &errno{project: 999, code: 999, message: "ERROR"}
)

func NewErrno

func NewErrno(project uint32, code uint16, msg string) Errno

type Event

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

Event provides contextual information about a log message.

func (*Event) Entry

func (e *Event) Entry() Entry

func (*Event) Fields added in v1.1.1

func (e *Event) Fields() []Field

func (*Event) File

func (e *Event) File() string

func (*Event) Level

func (e *Event) Level() Level

func (*Event) Line

func (e *Event) Line() int

func (*Event) Time

func (e *Event) Time() time.Time

type Field added in v1.1.1

type Field struct {
	Key string
	Val Value
}

func Any added in v1.1.1

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

func Array added in v1.1.1

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

func Bool added in v1.1.1

func Bool(key string, val bool) Field

Bool constructs a field that carries a bool.

func Boolp added in v1.1.1

func Boolp(key string, val *bool) Field

Boolp constructs a field that carries a *bool. The returned Field will safely and explicitly represent `nil` when appropriate.

func Bools added in v1.1.1

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

func Float32 added in v1.1.1

func Float32(key string, val float32) Field

Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float32p added in v1.1.1

func Float32p(key string, val *float32) Field

Float32p constructs a field that carries a *float32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Float32s added in v1.1.1

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

func Float64 added in v1.1.1

func Float64(key string, val float64) Field

Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float64p added in v1.1.1

func Float64p(key string, val *float64) Field

Float64p constructs a field that carries a *float64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Float64s added in v1.1.1

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

func Int added in v1.1.1

func Int(key string, val int) Field

Int constructs a field with the given key and value.

func Int16 added in v1.1.1

func Int16(key string, val int16) Field

Int16 constructs a field with the given key and value.

func Int16p added in v1.1.1

func Int16p(key string, val *int16) Field

Int16p constructs a field that carries a *int16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int16s added in v1.1.1

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

func Int32 added in v1.1.1

func Int32(key string, val int32) Field

Int32 constructs a field with the given key and value.

func Int32p added in v1.1.1

func Int32p(key string, val *int32) Field

Int32p constructs a field that carries a *int32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int32s added in v1.1.1

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

func Int64 added in v1.1.1

func Int64(key string, val int64) Field

Int64 constructs a field with the given key and value.

func Int64p added in v1.1.1

func Int64p(key string, val *int64) Field

Int64p constructs a field that carries a *int64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int64s added in v1.1.1

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

func Int8 added in v1.1.1

func Int8(key string, val int8) Field

Int8 constructs a field with the given key and value.

func Int8p added in v1.1.1

func Int8p(key string, val *int8) Field

Int8p constructs a field that carries a *int8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Int8s added in v1.1.1

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

func Intp added in v1.1.1

func Intp(key string, val *int) Field

Intp constructs a field that carries a *int. The returned Field will safely and explicitly represent `nil` when appropriate.

func Ints added in v1.1.1

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

func Message

func Message(format string, args ...interface{}) Field

func Object added in v1.1.1

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

func Reflect added in v1.1.1

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

Reflect constructs a field with the given key and an arbitrary object.

func String added in v1.1.1

func String(key string, val string) Field

String constructs a field with the given key and value.

func Stringp added in v1.1.1

func Stringp(key string, val *string) Field

Stringp constructs a field that carries a *string. The returned Field will safely and explicitly represent `nil` when appropriate.

func Strings added in v1.1.1

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

func Uint added in v1.1.1

func Uint(key string, val uint) Field

Uint constructs a field with the given key and value.

func Uint16 added in v1.1.1

func Uint16(key string, val uint16) Field

Uint16 constructs a field with the given key and value.

func Uint16p added in v1.1.1

func Uint16p(key string, val *uint16) Field

Uint16p constructs a field that carries a *uint16. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint16s added in v1.1.1

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

func Uint32 added in v1.1.1

func Uint32(key string, val uint32) Field

Uint32 constructs a field with the given key and value.

func Uint32p added in v1.1.1

func Uint32p(key string, val *uint32) Field

Uint32p constructs a field that carries a *uint32. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint32s added in v1.1.1

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

func Uint64 added in v1.1.1

func Uint64(key string, val uint64) Field

Uint64 constructs a field with the given key and value.

func Uint64p added in v1.1.1

func Uint64p(key string, val *uint64) Field

Uint64p constructs a field that carries a *uint64. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint64s added in v1.1.1

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

func Uint8 added in v1.1.1

func Uint8(key string, val uint8) Field

Uint8 constructs a field with the given key and value.

func Uint8p added in v1.1.1

func Uint8p(key string, val *uint8) Field

Uint8p constructs a field that carries a *uint8. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uint8s added in v1.1.1

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

func Uintp added in v1.1.1

func Uintp(key string, val *uint) Field

Uintp constructs a field that carries a *uint. The returned Field will safely and explicitly represent `nil` when appropriate.

func Uints added in v1.1.1

func Uints(key string, val []uint) 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 {
	LifeCycle
	Filter(level Level, e Entry, fields []Field) 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 Float32sValue added in v1.1.1

type Float32sValue []float32

func (Float32sValue) Encode added in v1.1.1

func (v Float32sValue) Encode(enc Encoder) error

type Float64Value added in v1.1.1

type Float64Value float64

func (Float64Value) Encode added in v1.1.1

func (v Float64Value) Encode(enc Encoder) error

type Float64sValue added in v1.1.1

type Float64sValue []float64

func (Float64sValue) Encode added in v1.1.1

func (v Float64sValue) Encode(enc Encoder) error

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

func (Int16sValue) Encode added in v1.1.1

func (v Int16sValue) Encode(enc Encoder) error

type Int32sValue added in v1.1.1

type Int32sValue []int32

func (Int32sValue) Encode added in v1.1.1

func (v Int32sValue) Encode(enc Encoder) error

type Int64Value added in v1.1.1

type Int64Value int64

func (Int64Value) Encode added in v1.1.1

func (v Int64Value) Encode(enc Encoder) error

type Int64sValue added in v1.1.1

type Int64sValue []int64

func (Int64sValue) Encode added in v1.1.1

func (v Int64sValue) Encode(enc Encoder) error

type Int8sValue added in v1.1.1

type Int8sValue []int8

func (Int8sValue) Encode added in v1.1.1

func (v Int8sValue) Encode(enc Encoder) error

type IntsValue added in v1.1.1

type IntsValue []int

func (IntsValue) Encode added in v1.1.1

func (v IntsValue) Encode(enc Encoder) error

type JSONLayout added in v1.1.1

type JSONLayout struct {
	LineBreak bool `PluginAttribute:"lineBreak,default=true"`
}

func (*JSONLayout) ToBytes added in v1.1.1

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

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 {
	BaseFilter
	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(level Level, e Entry, fields []Field) Result

type LevelMatchFilter

type LevelMatchFilter struct {
	BaseFilter
	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(level Level, e Entry, fields []Field) Result

type LevelRangeFilter

type LevelRangeFilter struct {
	BaseFilter
	MinLevel Level `PluginAttribute:"minLevel"`
	MaxLevel Level `PluginAttribute:"maxLevel"`
}

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(level Level, e Entry, fields []Field) 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, level ...Level) *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) Filter

func (l *Logger) Filter() Filter

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) ContextEntry

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

func (*Logger) WithSkip

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

WithSkip 创建包含 skip 信息的 Entry 。

func (*Logger) WithTag

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

WithTag 创建包含 tag 信息的 Entry 。

type MessageValue added in v1.1.1

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

func (MessageValue) Encode added in v1.1.1

func (v MessageValue) Encode(enc Encoder) error

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

func (ObjectValue) Encode added in v1.1.1

func (v ObjectValue) Encode(enc Encoder) error

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{}
}

func (ReflectValue) Encode added in v1.1.1

func (v ReflectValue) Encode(enc Encoder) error

type Result

type Result int

func ParseResult

func ParseResult(s string) (Result, error)

type RollingFileAppender

type RollingFileAppender struct {
	BaseAppender
}

func (*RollingFileAppender) Append

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

type SimpleEntry

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

SimpleEntry is an Entry implementation that has no context.

func (*SimpleEntry) Context

func (e *SimpleEntry) Context() context.Context

func (SimpleEntry) Debug

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

Debug outputs log with level DebugLevel.

func (SimpleEntry) Debugf

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

Debugf outputs log with level DebugLevel.

func (SimpleEntry) Debugw added in v1.1.1

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

Debugw outputs log with level DebugLevel.

func (*SimpleEntry) Errno

func (e *SimpleEntry) Errno() Errno

func (SimpleEntry) Error

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

Error outputs log with level ErrorLevel.

func (SimpleEntry) Errorf

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

Errorf outputs log with level ErrorLevel.

func (SimpleEntry) Errorw added in v1.1.1

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

Errorw outputs log with level ErrorLevel.

func (SimpleEntry) Fatal

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

Fatal outputs log with level FatalLevel.

func (SimpleEntry) Fatalf

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

Fatalf outputs log with level FatalLevel.

func (SimpleEntry) Fatalw added in v1.1.1

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

Fatalw outputs log with level FatalLevel.

func (SimpleEntry) Info

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

Info outputs log with level InfoLevel.

func (SimpleEntry) Infof

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

Infof outputs log with level InfoLevel.

func (SimpleEntry) Infow added in v1.1.1

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

Infow outputs log with level InfoLevel.

func (SimpleEntry) Panic

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

Panic outputs log with level PanicLevel.

func (SimpleEntry) Panicf

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

Panicf outputs log with level PanicLevel.

func (SimpleEntry) Panicw added in v1.1.1

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

Panicw outputs log with level PanicLevel.

func (*SimpleEntry) Tag

func (e *SimpleEntry) Tag() string

func (SimpleEntry) Trace

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

Trace outputs log with level TraceLevel.

func (SimpleEntry) Tracef

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

Tracef outputs log with level TraceLevel.

func (SimpleEntry) Tracew added in v1.1.1

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

Tracew outputs log with level TraceLevel.

func (SimpleEntry) Warn

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

Warn outputs log with level WarnLevel.

func (SimpleEntry) Warnf

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

Warnf outputs log with level WarnLevel.

func (SimpleEntry) Warnw added in v1.1.1

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

Warnw outputs log with level WarnLevel.

func (SimpleEntry) WithContext

func (e SimpleEntry) WithContext(ctx context.Context) ContextEntry

func (SimpleEntry) WithSkip

func (e SimpleEntry) WithSkip(n int) SimpleEntry

func (SimpleEntry) WithTag

func (e SimpleEntry) WithTag(tag string) SimpleEntry

type StringValue added in v1.1.1

type StringValue string

func (StringValue) Encode added in v1.1.1

func (v StringValue) Encode(enc Encoder) error

type StringsValue added in v1.1.1

type StringsValue []string

func (StringsValue) Encode added in v1.1.1

func (v StringsValue) Encode(enc Encoder) error

type TagFilter added in v1.1.1

type TagFilter struct {
	BaseFilter
	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(level Level, e Entry, fields []Field) Result

func (*TagFilter) Init added in v1.1.1

func (f *TagFilter) Init() error

type TimeFilter

type TimeFilter struct {
	BaseFilter
	Timezone string `PluginAttribute:"timezone,default=Local"`
	Start    string `PluginAttribute:"start"`
	End      string `PluginAttribute:"end"`
	TimeFunc func() time.Time
	// 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(level Level, e Entry, fields []Field) Result

func (*TimeFilter) Init

func (f *TimeFilter) Init() error

type Uint16sValue added in v1.1.1

type Uint16sValue []uint16

func (Uint16sValue) Encode added in v1.1.1

func (v Uint16sValue) Encode(enc Encoder) error

type Uint32sValue added in v1.1.1

type Uint32sValue []uint32

func (Uint32sValue) Encode added in v1.1.1

func (v Uint32sValue) Encode(enc Encoder) error

type Uint64Value added in v1.1.1

type Uint64Value uint64

func (Uint64Value) Encode added in v1.1.1

func (v Uint64Value) Encode(enc Encoder) error

type Uint64sValue added in v1.1.1

type Uint64sValue []uint64

func (Uint64sValue) Encode added in v1.1.1

func (v Uint64sValue) Encode(enc Encoder) error

type Uint8sValue added in v1.1.1

type Uint8sValue []uint8

func (Uint8sValue) Encode added in v1.1.1

func (v Uint8sValue) Encode(enc Encoder) error

type UintsValue added in v1.1.1

type UintsValue []uint

func (UintsValue) Encode added in v1.1.1

func (v UintsValue) Encode(enc Encoder) error

type Value added in v1.1.1

type Value interface {
	Encode(enc Encoder) error
}

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
layout command
tagfilter command

Jump to

Keyboard shortcuts

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