qlog

package
v1.3.22 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: BSD-3-Clause Imports: 14 Imported by: 0

README

日志API设计

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppFileErrorLog

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

func Debugf

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

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

func Errorf

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

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

func Fatalf

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

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

func HookSystemLog

func HookSystemLog(args map[string]string) zap.Option

func Infof

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

func Infow

func Infow(msg string, keysAndValues ...interface{})

func NewFileSync

func NewFileSync(filename string, mode fsutil.WriterMode) zapcore.WriteSyncer

func NewLogger

func NewLogger(cfg *Config) *zap.Logger

func Panicf

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

func Reset

func Reset()

func ServerErrorLog

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

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

func Setup

func Setup(cfg *Config)

func Warnf

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

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

func WriteFileLog

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

Types

type Config

type Config struct {
	Level        string // 等级
	Filepath     string // 日志文件
	ErrFilepath  string // err文件
	IsProduction bool   // 是否product模式

	Conf *zap.Config
}

配置参数

func NewConfig

func NewConfig(level string) *Config

func (*Config) Build

func (c *Config) Build() *zap.Logger

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