log

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Undefined    = "_undef"
	RequestIn    = "_request_in"
	RequestOut   = "_request_out"
	HttpSuccess  = "_http_success"
	HttpFailure  = "_http_failure"
	GRPCSuccess  = "_grpc_success"
	GRPCFailure  = "_grpc_failure"
	MysqlSuccess = "_mysql_success"
	MysqlFailure = "_mysql_failure"
	RedisSuccess = "_redis_success"
	RedisFailure = "_redis_failure"
)
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 (
	RootLoggerName      = "Root"
	AsyncRootLoggerName = "AsyncRoot"
)
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 Refresh

func Refresh(fileName string) error

Refresh 加载日志配置文件。

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 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 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, msg Message) 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) 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) 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) 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) 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) 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) 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) WithSkip

func (e ContextEntry) WithSkip(n int) ContextEntry

func (ContextEntry) WithTag

func (e ContextEntry) WithTag(tag string) ContextEntry

type CountingNoOpAppender

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

CountingNoOpAppender is a no-operation Appender that counts events.

func (*CountingNoOpAppender) Append

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

func (*CountingNoOpAppender) Count

func (c *CountingNoOpAppender) Count() int64

func (*CountingNoOpAppender) Start

func (c *CountingNoOpAppender) Start() error

func (*CountingNoOpAppender) Stop

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

type DefaultLayout

type DefaultLayout struct {
	LineBreak  bool       `PluginAttribute:"lineBreak,default=true"`
	ColorStyle ColorStyle `PluginAttribute:"colorStyle,default=none"`
}

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, _ Message) Result

func (*DenyAllFilter) Start

func (f *DenyAllFilter) Start() error

func (*DenyAllFilter) Stop

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

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

func (e *Event) File() string

func (*Event) Level

func (e *Event) Level() Level

func (*Event) Line

func (e *Event) Line() int

func (*Event) Msg

func (e *Event) Msg() Message

func (*Event) Time

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

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, msg Message) Result
}

Filter is an interface that tells the logger a log message should be dropped when the Filter method returns ResultDeny.

type FormattedMessage

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

FormattedMessage can convert itself to text by fmt.Sprint or fmt.Sprintf.

func (*FormattedMessage) Text

func (msg *FormattedMessage) Text() string

type Initializer

type Initializer interface {
	Init() error
}

type Int64

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

func (*Int64) Add

func (i *Int64) Add(delta int64) int64

Add wrapper for atomic.AddInt64.

func (*Int64) CompareAndSwap

func (i *Int64) CompareAndSwap(old, new int64) bool

CompareAndSwap wrapper for atomic.CompareAndSwapInt64.

func (*Int64) Load

func (i *Int64) Load() int64

Load wrapper for atomic.LoadInt64.

func (*Int64) Store

func (i *Int64) Store(val int64)

Store wrapper for atomic.StoreInt64.

func (*Int64) Swap

func (i *Int64) Swap(new int64) int64

Swap wrapper for atomic.SwapInt64.

type JsonMessage

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

JsonMessage can convert itself to text by json.Marshal.

func (*JsonMessage) Text

func (msg *JsonMessage) Text() string

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, msg Message) 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, msg Message) 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, msg Message) 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(level ...Level) *Logger

GetLogger 获取名字为声明位置的包名的 *Logger 对象。

func NewLogger

func NewLogger(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) 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) 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) 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) 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) 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) 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) 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 Message

type Message interface {
	Text() string
}

Message is an interface that its implementations can be converted to text.

func NewFormattedMessage

func NewFormattedMessage(format string, args []interface{}) Message

func NewJsonMessage

func NewJsonMessage(data interface{}) Message

type NoCopy

type NoCopy struct{}

NoCopy may be embedded into structs which must not be copied after the first use.

See https://golang.org/issues/8005#issuecomment-190753527 for details.

func (*NoCopy) Lock

func (*NoCopy) Lock()

Lock is a no-op used by -copylocks checker from `go vet`.

func (*NoCopy) Unlock

func (*NoCopy) Unlock()

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

func (c *NullAppender) Start() error

func (*NullAppender) Stop

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

type OptimizedMessage

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

OptimizedMessage uses atomic.Value to store formatted text. Tests show that you can use OptimizedMessage to improve the performance of the Text method when you call the Text method more than once.

func (*OptimizedMessage) Once

func (msg *OptimizedMessage) Once(fn func() string) string

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 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) 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) 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) 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) 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) 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) 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) 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 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, msg Message) Result

func (*TimeFilter) Init

func (f *TimeFilter) Init() error

type Value

type Value struct {
	atomic.Value
	// contains filtered or unexported fields
}

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

Jump to

Keyboard shortcuts

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