Documentation ¶
Index ¶
- Constants
- Variables
- func Caller(skip int, fast bool) (file string, line int, loaded bool)
- func Refresh(fileName string) error
- func RegisterConverter(fn util.Converter)
- func RegisterPlugin(name string, typ string, i interface{})
- func RegisterReader(r Reader, ext ...string)
- type Appender
- type AppenderRef
- type BaseAppender
- type BaseFilter
- type ColorStyle
- type CompositeFilter
- type ConsoleAppender
- type ContextEntry
- func (e *ContextEntry) Context() context.Context
- func (e ContextEntry) Debug(args ...interface{}) *Event
- func (e ContextEntry) Debugf(format string, args ...interface{}) *Event
- func (e *ContextEntry) Errno() Errno
- func (e ContextEntry) Error(errno Errno, args ...interface{}) *Event
- func (e ContextEntry) Errorf(errno Errno, format string, args ...interface{}) *Event
- func (e ContextEntry) Fatal(args ...interface{}) *Event
- func (e ContextEntry) Fatalf(format string, args ...interface{}) *Event
- func (e ContextEntry) Info(args ...interface{}) *Event
- func (e ContextEntry) Infof(format string, args ...interface{}) *Event
- func (e ContextEntry) Panic(args ...interface{}) *Event
- func (e ContextEntry) Panicf(format string, args ...interface{}) *Event
- func (e *ContextEntry) Tag() string
- func (e ContextEntry) Trace(args ...interface{}) *Event
- func (e ContextEntry) Tracef(format string, args ...interface{}) *Event
- func (e ContextEntry) Warn(args ...interface{}) *Event
- func (e ContextEntry) Warnf(format string, args ...interface{}) *Event
- func (e ContextEntry) WithSkip(n int) ContextEntry
- func (e ContextEntry) WithTag(tag string) ContextEntry
- type CountingNoOpAppender
- type DefaultLayout
- type DenyAllFilter
- type Entry
- type Errno
- type Event
- type FileAppender
- type FileWriter
- type Filter
- type FormattedMessage
- type Initializer
- type Int64
- type JsonMessage
- type Layout
- type Level
- type LevelFilter
- type LevelMatchFilter
- type LevelRangeFilter
- type LifeCycle
- type Logger
- func (l *Logger) Appenders() []Appender
- func (l *Logger) Debug(args ...interface{}) *Event
- func (l *Logger) Debugf(format string, args ...interface{}) *Event
- func (l *Logger) Error(args ...interface{}) *Event
- func (l *Logger) Errorf(format string, args ...interface{}) *Event
- func (l *Logger) Fatal(args ...interface{}) *Event
- func (l *Logger) Fatalf(format string, args ...interface{}) *Event
- func (l *Logger) Filter() Filter
- func (l *Logger) Info(args ...interface{}) *Event
- func (l *Logger) Infof(format string, args ...interface{}) *Event
- func (l *Logger) Level() Level
- func (l *Logger) Name() string
- func (l *Logger) Panic(args ...interface{}) *Event
- func (l *Logger) Panicf(format string, args ...interface{}) *Event
- func (l *Logger) Trace(args ...interface{}) *Event
- func (l *Logger) Tracef(format string, args ...interface{}) *Event
- func (l *Logger) Warn(args ...interface{}) *Event
- func (l *Logger) Warnf(format string, args ...interface{}) *Event
- func (l *Logger) WithContext(ctx context.Context) ContextEntry
- func (l *Logger) WithSkip(n int) SimpleEntry
- func (l *Logger) WithTag(tag string) SimpleEntry
- type Message
- type NoCopy
- type Node
- type NullAppender
- type OptimizedMessage
- type Plugin
- type PluginTag
- type Reader
- type Result
- type RollingFileAppender
- type SimpleEntry
- func (e *SimpleEntry) Context() context.Context
- func (e SimpleEntry) Debug(args ...interface{}) *Event
- func (e SimpleEntry) Debugf(format string, args ...interface{}) *Event
- func (e *SimpleEntry) Errno() Errno
- func (e SimpleEntry) Error(args ...interface{}) *Event
- func (e SimpleEntry) Errorf(format string, args ...interface{}) *Event
- func (e SimpleEntry) Fatal(args ...interface{}) *Event
- func (e SimpleEntry) Fatalf(format string, args ...interface{}) *Event
- func (e SimpleEntry) Info(args ...interface{}) *Event
- func (e SimpleEntry) Infof(format string, args ...interface{}) *Event
- func (e SimpleEntry) Panic(args ...interface{}) *Event
- func (e SimpleEntry) Panicf(format string, args ...interface{}) *Event
- func (e *SimpleEntry) Tag() string
- func (e SimpleEntry) Trace(args ...interface{}) *Event
- func (e SimpleEntry) Tracef(format string, args ...interface{}) *Event
- func (e SimpleEntry) Warn(args ...interface{}) *Event
- func (e SimpleEntry) Warnf(format string, args ...interface{}) *Event
- func (e SimpleEntry) WithContext(ctx context.Context) ContextEntry
- func (e SimpleEntry) WithSkip(n int) SimpleEntry
- func (e SimpleEntry) WithTag(tag string) SimpleEntry
- type TimeFilter
- type Value
- type Writer
- type XMLReader
Constants ¶
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" )
const ( ResultAccept = Result(iota) ResultDeny )
const ( ColorStyleNone = ColorStyle(iota) ColorStyleNormal ColorStyleBright )
const ( NoneLevel = Level(iota) TraceLevel DebugLevel InfoLevel WarnLevel ErrorLevel PanicLevel FatalLevel OffLevel )
const ( RootLoggerName = "Root" AsyncRootLoggerName = "AsyncRoot" )
const ( PluginTypeAppender = "Appender" PluginTypeFilter = "Filter" PluginTypeLayout = "Layout" )
Variables ¶
var ( // Status records events that occur in the logging system. Status = NewLogger("", ErrorLevel) )
var Writers = &writers{ writers: make(map[string]*sharedWriter), }
Writers manages the Get and Release of Writer(s).
Functions ¶
func RegisterConverter ¶
RegisterConverter registers Converter for non-primitive type such as time.Time, time.Duration, or other user-defined value type.
func RegisterPlugin ¶
RegisterPlugin registers a Plugin, `i` is used to obtain the type of Plugin.
Types ¶
type Appender ¶
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"` }
type DenyAllFilter ¶
type DenyAllFilter struct{}
DenyAllFilter causes all logging events to be dropped.
func (*DenyAllFilter) Start ¶
func (f *DenyAllFilter) Start() error
func (*DenyAllFilter) Stop ¶
func (f *DenyAllFilter) Stop(ctx context.Context)
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event provides contextual information about a log message.
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)
type Filter ¶
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) CompareAndSwap ¶
CompareAndSwap wrapper for atomic.CompareAndSwapInt64.
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 Level ¶
type Level int32
Level used for identifying the severity of an event.
func ParseLevel ¶
ParseLevel parses string to a level, and returns error if the conversion fails.
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.
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.
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.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
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 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.
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 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) Init ¶
func (f *TimeFilter) Init() error
type Writer ¶
Writer is io.Writer with a name and a Stop method.
func NewFileWriter ¶
NewFileWriter returns a FileWriter that a Writer implementation.