goo_log

package
v1.1.200 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 11 Imported by: 5

README

日志级别

  • Fatal 致命的
  • Panic 严重的
  • Error 错误的
  • Warn 告警的
  • Info 信息的
  • Debug 调试的

文件说明

  • log.go 对外开放的方法,默认console适配器,属于第1层级
  • logger.go log对象,像 SetAdapter WithHook 是项目及全局方法,属于第2层级
  • entry.go 实体类,每次产生一条log时,都要 new 实体类,主要处理消息内容、标签、附加数据等,属于第3层级
  • message.go 消息内容对象,包装每条消息包含的字段信息
  • adapter.go 适配器
  • console.go 控制台适配器
  • file.go 文件适配器
  • file_options.go 文件适配器 选项

文件适配器

  • filepath 日志保存目录
  • filename 日志文件名,使用 yyyymmdd.log
  • maxSize 文件大小最大值,默认512M,超过后,会切割文件
  • FilePathOption() 定义文件路径
  • FileMaxSizeOption() 定义文件大小最大值

输出对象

  • console
  • file
  • kafka
  • es

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LevelText = map[Level]string{
		DEBUG: "DEBUG",
		INFO:  "INFO",
		WARN:  "WARN",
		ERROR: "ERROR",
		PANIC: "PANIC",
		FATAL: "FATAL",
	}
)

Functions

func Debug

func Debug(v ...interface{})

func DebugF added in v1.0.34

func DebugF(format string, v ...interface{})

func Error

func Error(v ...interface{})

func ErrorF added in v1.0.34

func ErrorF(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func FatalF added in v1.0.34

func FatalF(format string, v ...interface{})

func Info

func Info(v ...interface{})

func InfoF added in v1.0.34

func InfoF(format string, v ...interface{})

func Panic

func Panic(v ...interface{})

func PanicF added in v1.0.34

func PanicF(format string, v ...interface{})

func SetAdapter

func SetAdapter(adapter Adapter)

func Warn

func Warn(v ...interface{})

func WarnF added in v1.0.34

func WarnF(format string, v ...interface{})

func WithHook added in v1.1.1

func WithHook(fns ...func(msg *Message))

Types

type Adapter

type Adapter interface {
	Write(msg *Message)
}

type ConsoleAdapter

type ConsoleAdapter struct {
}

func (*ConsoleAdapter) Write

func (ca *ConsoleAdapter) Write(msg *Message)

type DataField added in v1.1.1

type DataField struct {
	Field string
	Value interface{}
}

type Entry

type Entry struct {
	Tags  []string
	Data  []DataField
	Trace []string
	// contains filtered or unexported fields
}

func NewEntry

func NewEntry(l *Logger) *Entry

func WithField

func WithField(field string, value interface{}) *Entry

func WithTag added in v1.0.15

func WithTag(tags ...string) *Entry

func WithTrace added in v1.0.43

func WithTrace() *Entry

func (*Entry) Debug

func (entry *Entry) Debug(v ...interface{})

func (*Entry) DebugF added in v1.0.26

func (entry *Entry) DebugF(format string, v ...interface{})

func (*Entry) Error

func (entry *Entry) Error(v ...interface{})

func (*Entry) ErrorF added in v1.0.26

func (entry *Entry) ErrorF(format string, v ...interface{})

func (*Entry) Fatal

func (entry *Entry) Fatal(v ...interface{})

func (*Entry) FatalF added in v1.0.26

func (entry *Entry) FatalF(format string, v ...interface{})

func (*Entry) Info

func (entry *Entry) Info(v ...interface{})

func (*Entry) InfoF added in v1.0.26

func (entry *Entry) InfoF(format string, v ...interface{})

func (*Entry) Panic

func (entry *Entry) Panic(v ...interface{})

func (*Entry) PanicF added in v1.0.26

func (entry *Entry) PanicF(format string, v ...interface{})

func (*Entry) Warn

func (entry *Entry) Warn(v ...interface{})

func (*Entry) WarnF added in v1.0.26

func (entry *Entry) WarnF(format string, v ...interface{})

func (*Entry) WithField

func (entry *Entry) WithField(field string, value interface{}) *Entry

func (*Entry) WithTag added in v1.0.15

func (entry *Entry) WithTag(tags ...string) *Entry

func (*Entry) WithTrace added in v1.0.43

func (entry *Entry) WithTrace() *Entry

type FileAdapter

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

func NewFileAdapter

func NewFileAdapter(opt ...FileOption) *FileAdapter

func (*FileAdapter) Write

func (fa *FileAdapter) Write(msg *Message)

type FileOption added in v1.1.1

type FileOption interface {
	// contains filtered or unexported methods
}

func FileMaxSizeOption

func FileMaxSizeOption(maxSize int64) FileOption

func FilePathOption added in v1.1.1

func FilePathOption(filepath string) FileOption

type Level

type Level int
const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	PANIC
	FATAL
)

type Logger

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

func Default

func Default() *Logger

func New

func New(adapter Adapter) *Logger

func NewConsoleLog added in v1.1.1

func NewConsoleLog() *Logger

func NewFileLog added in v1.1.1

func NewFileLog(opts ...FileOption) *Logger

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

func (*Logger) DebugF added in v1.0.26

func (l *Logger) DebugF(format string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

func (*Logger) ErrorF added in v1.0.26

func (l *Logger) ErrorF(format string, v ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

func (*Logger) FatalF added in v1.0.26

func (l *Logger) FatalF(format string, v ...interface{})

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

func (*Logger) InfoF added in v1.0.26

func (l *Logger) InfoF(format string, v ...interface{})

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{})

func (*Logger) PanicF added in v1.0.26

func (l *Logger) PanicF(format string, v ...interface{})

func (*Logger) SetAdapter

func (l *Logger) SetAdapter(adapter Adapter)

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

func (*Logger) WarnF added in v1.0.26

func (l *Logger) WarnF(format string, v ...interface{})

func (*Logger) WithField

func (l *Logger) WithField(field string, value interface{}) *Entry

func (*Logger) WithHook added in v1.1.1

func (l *Logger) WithHook(fns ...func(msg *Message))

func (*Logger) WithTag added in v1.0.15

func (l *Logger) WithTag(tags ...string) *Entry

func (*Logger) WithTrace added in v1.0.43

func (l *Logger) WithTrace() *Entry

type Message

type Message struct {
	Level   Level
	Message []interface{}
	Time    time.Time
	Entry   *Entry
}

func (*Message) JSON

func (msg *Message) JSON() []byte

Jump to

Keyboard shortcuts

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