Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func NewFormatterID() int
- func Trace(args ...interface{})
- func Tracef(format string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type BaseChannel
- func (c *BaseChannel) Close() error
- func (c *BaseChannel) GetFormatter() Formatter
- func (c *BaseChannel) GetLevel() Level
- func (c *BaseChannel) GetProperty(key string) string
- func (c *BaseChannel) Open() error
- func (c *BaseChannel) SetFormatter(formatter Formatter)
- func (c *BaseChannel) SetLevel(lv Level)
- func (c *BaseChannel) SetLogger(l *Logger)
- func (c *BaseChannel) SetProperty(key string, value string) error
- type Builder
- func (b *Builder) Debug(args ...interface{})
- func (b *Builder) Debugf(format string, args ...interface{})
- func (b *Builder) Error(args ...interface{})
- func (b *Builder) Errorf(format string, args ...interface{})
- func (b *Builder) Fatal(args ...interface{})
- func (b *Builder) Fatalf(format string, args ...interface{})
- func (b *Builder) Info(args ...interface{})
- func (b *Builder) Infof(format string, args ...interface{})
- func (b *Builder) Log(lv Level, args ...interface{})
- func (b *Builder) Logf(lv Level, format string, args ...interface{})
- func (b *Builder) Trace(args ...interface{})
- func (b *Builder) Tracef(format string, args ...interface{})
- func (b *Builder) Warn(args ...interface{})
- func (b *Builder) Warnf(format string, args ...interface{})
- func (b *Builder) WithFields(fields map[string]string) *Builder
- type Channel
- type Cond
- type Configurable
- type DateFormat
- type ElasticChannel
- type Entry
- type FileChannel
- type Formatter
- type JsonFormatter
- type Layout
- type Level
- type Logger
- func (l *Logger) AddChannel(c Channel)
- func (l *Logger) AddField(key, value string)
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Formatter() Formatter
- func (l *Logger) GetField(key string) string
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Level() Level
- func (l *Logger) Log(lv Level, args ...interface{})
- func (l *Logger) Logf(lv Level, format string, args ...interface{})
- func (l *Logger) Max() int
- func (l *Logger) Push(e *Entry)
- func (l *Logger) Run()
- func (l *Logger) SetFormatter(f Formatter)
- func (l *Logger) SetLevel(lv Level)
- func (l *Logger) SetMax(max int)
- func (l *Logger) SetSync(s bool)
- func (l *Logger) Start()
- func (l *Logger) Stop()
- func (l *Logger) Sync() bool
- func (l *Logger) Trace(args ...interface{})
- func (l *Logger) Tracef(format string, args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WithFields(fields map[string]string) *Builder
- func (l *Logger) Write(lv Level, fields map[string]string, skipFrames int, text string)
- type Queue
- type TerminalChannel
- type TextFormatter
- type UDPChannel
Constants ¶
View Source
const (
// 默认最大堆积消息数,超出则丢弃
DefaultMsgMax = 10000
)
View Source
const DefaultTextLayout = "%D [%L] [%F] %m"
Variables ¶
View Source
var ( ErrNotReady = fmt.Errorf("channel not ready") ErrNotSupport = fmt.Errorf("not support") )
Functions ¶
func NewFormatterID ¶
func NewFormatterID() int
Types ¶
type BaseChannel ¶
type BaseChannel struct {
// contains filtered or unexported fields
}
func (*BaseChannel) Close ¶
func (c *BaseChannel) Close() error
func (*BaseChannel) GetFormatter ¶
func (c *BaseChannel) GetFormatter() Formatter
func (*BaseChannel) GetLevel ¶
func (c *BaseChannel) GetLevel() Level
func (*BaseChannel) GetProperty ¶
func (c *BaseChannel) GetProperty(key string) string
func (*BaseChannel) Open ¶
func (c *BaseChannel) Open() error
func (*BaseChannel) SetFormatter ¶
func (c *BaseChannel) SetFormatter(formatter Formatter)
func (*BaseChannel) SetLevel ¶
func (c *BaseChannel) SetLevel(lv Level)
func (*BaseChannel) SetLogger ¶
func (c *BaseChannel) SetLogger(l *Logger)
func (*BaseChannel) SetProperty ¶
func (c *BaseChannel) SetProperty(key string, value string) error
type Channel ¶
type Channel interface { Configurable SetLogger(l *Logger) Name() string Open() error Close() error Write(msg *Entry) }
func NewTerminal ¶
func NewTerminal() Channel
type Configurable ¶
type DateFormat ¶
type DateFormat struct {
Tokens []dfToken
}
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings yyyy-MM-ddTHH:mm:ss
func (*DateFormat) Parse ¶
func (d *DateFormat) Parse(layout string)
type ElasticChannel ¶
type ElasticChannel struct { BaseChannel URL string Username string Password string Timeout time.Duration // 发送超时,默认10s Retry int // 失败重试次数,默认不重试,直接丢弃 Bulk int // 用于配置一个批次发送多少条日志,默认1条 Index string // 索引名,按照日期分类? // contains filtered or unexported fields }
官方的API: https://github.com/elastic/go-elasticsearch 但是比较厚重,这里只需要Index https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html TODO:支持Bulk模式,需要ndjson编码 formatter编码格式必须是json格式
func (*ElasticChannel) Close ¶
func (c *ElasticChannel) Close() error
func (*ElasticChannel) Name ¶
func (c *ElasticChannel) Name() string
func (*ElasticChannel) Open ¶
func (c *ElasticChannel) Open() error
func (*ElasticChannel) SetProperty ¶
func (c *ElasticChannel) SetProperty(key string, value string) error
type Entry ¶
type FileChannel ¶
type FileChannel struct { BaseChannel // contains filtered or unexported fields }
文件输出,rotate strategy
func (*FileChannel) Close ¶
func (c *FileChannel) Close() error
func (*FileChannel) Name ¶
func (c *FileChannel) Name() string
func (*FileChannel) Open ¶
func (c *FileChannel) Open() error
func (*FileChannel) SetProperty ¶
func (c *FileChannel) SetProperty(key string, value string) error
func (*FileChannel) Write ¶
func (c *FileChannel) Write(msg *Entry)
type Formatter ¶
type Formatter interface { ID() int // 唯一ID,用于服用格式化结果 Name() string Parse(layout string) error Format(entry *Entry) ([]byte, error) }
func NewFormatter ¶
func NewTextFormatter ¶
type JsonFormatter ¶
格式配置,例如:time=%D message=%m level=%l
func (*JsonFormatter) ID ¶
func (f *JsonFormatter) ID() int
func (*JsonFormatter) Name ¶
func (f *JsonFormatter) Name() string
func (*JsonFormatter) Parse ¶
func (f *JsonFormatter) Parse(layout string) error
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 支持同步或者异步日志输出,默认使用同步控制台输出
func (*Logger) AddChannel ¶
func (*Logger) SetFormatter ¶
type TerminalChannel ¶
type TerminalChannel struct { BaseChannel // contains filtered or unexported fields }
控制台输出
func (*TerminalChannel) Name ¶
func (c *TerminalChannel) Name() string
func (*TerminalChannel) SetProperty ¶
func (c *TerminalChannel) SetProperty(key string, value string) error
func (*TerminalChannel) Write ¶
func (c *TerminalChannel) Write(msg *Entry)
type TextFormatter ¶
type TextFormatter struct {
// contains filtered or unexported fields
}
func (*TextFormatter) ID ¶
func (f *TextFormatter) ID() int
func (*TextFormatter) Name ¶
func (f *TextFormatter) Name() string
func (*TextFormatter) Parse ¶
func (f *TextFormatter) Parse(layout string) error
type UDPChannel ¶
type UDPChannel struct { BaseChannel // contains filtered or unexported fields }
UDP协议
func (*UDPChannel) Close ¶
func (c *UDPChannel) Close() error
func (*UDPChannel) Name ¶
func (c *UDPChannel) Name() string
func (*UDPChannel) Open ¶
func (c *UDPChannel) Open() error
func (*UDPChannel) SetProperty ¶
func (c *UDPChannel) SetProperty(key string, value string) error
func (*UDPChannel) Write ¶
func (c *UDPChannel) Write(msg *Entry)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.