log

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

README

日志API设计

日志API需求
  1. 日志分级;
  2. 日志存档(文件,ELK等);
  3. 日志API
日志API实现
  1. log包提供一个对外部稳定的API,外部不必关注log包内部是如何实现(内部目前使用uber zap);
  2. 业务package只需要import log即可使用日志,不必在new其它对象;
  3. 通过不同的API名称实现日志分级
接口 作用
log.Setup() 设置参数
log.Debugf() 调试日志
log.Infof() 信息日志
log.Warnf() 警告日志
log.Errorf() 错误日志
log.Fatalf() 错误日志,程序不能继续执行

Documentation

Index

Constants

View Source
const (
	TimestampFormat = "2006-01-02 15:04:05.999"
)

Variables

This section is empty.

Functions

func AppFileErrorLog

func AppFileErrorLog(format string, a ...interface{}) error

func DPanicf

func DPanicf(format string, args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func IsTerminal

func IsTerminal(w io.Writer) bool

func Panicf

func Panicf(format string, args ...interface{})

func ServerErrorLog

func ServerErrorLog(format string, a ...interface{})

用于在初始化服务时的错误日志

func Setup

func Setup(isProduction, enableSysLog bool, level, filepath, args string)

func Shutdown

func Shutdown()

func Warnf

func Warnf(format string, args ...interface{})

func WriteFileLog

func WriteFileLog(filename, format string, a ...interface{}) error

Types

type FileLogger

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

记录日志到文件

func NewFileWriter

func NewFileWriter(prefix string) *FileLogger

func (*FileLogger) Sync

func (w *FileLogger) Sync() error

func (*FileLogger) Write

func (w *FileLogger) Write(data []byte) error

type Hooker

type Hooker interface {
	Name() string
	Fire(entry zapcore.Entry) error
}

func NewSyslogHook

func NewSyslogHook(network, raddr string, priority syslog.Priority, tag string) Hooker

Creates a hook to be added to an instance of logger. This is called with `hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_DEBUG, "")`

type SyslogHook

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

SyslogHook to send logs via syslog.

func (*SyslogHook) Fire

func (h *SyslogHook) Fire(entry zapcore.Entry) error

func (*SyslogHook) Name

func (h *SyslogHook) Name() string

Jump to

Keyboard shortcuts

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