zdpgo_zap

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 7 Imported by: 3

README

zdpgo_zap

基于zap二次封装的日志库

功能

  • 持久化日志
  • json日志
  • 区分测试环境和生产环境
  • 全局日志
  • 日志备份

版本日志

  • 版本0.1.0:2022年1月30日
  • 版本0.1.1:2022年1月30日
  • 版本0.2.0:2022年2月10日 新增日志备份功能
  • 版本0.2.1:2022年2月10日 新增自动创建日志目录功能
  • 版本0.2.2:2022年2月11日 将日志对象开放给外部使用

快速入门

package main

import "github.com/zhangdapeng520/zdpgo_zap"

func main() {
	l := zdpgo_zap.New(zdpgo_zap.ZapConfig{
		Debug:        true,
		OpenGlobal:   true,
		OpenFileName: false,
	})
	l.Debug("debug日志", "a", 111, "b", 22.22, "c", true, "d", "bbb")
	l.Info("info日志", "a", 111, "b", 22.22, "c", true, "d", "bbb")
	l.Warning("warning日志", "a", 111, "b", 22.22, "c", true, "d", "bbb")
	l.Error("error日志", "a", 111, "b", 22.22, "c", true, "d", "bbb")
}

创建日志的便捷方式

func TestZap_Debug(t *testing.T) {
	l := NewDebug()
	l.Debug("日志。。。")
	l.Info("日志。。。")
	l.Warning("日志。。。")
	l.Error("日志。。。")
}

func TestZap_Product(t *testing.T) {
	l := NewProduct()
	l.Debug("日志。。。")
	l.Info("日志。。。")
	l.Warning("日志。。。")
	l.Error("日志。。。")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, kvs ...interface{})

Debug 记录debug类型的日志

func Error

func Error(msg string, kvs ...interface{})

Error 记录error类型的日志

func Fatal

func Fatal(msg string, kvs ...interface{})

Fatal 记录fatal类型的日志

func Info

func Info(msg string, kvs ...interface{})

Info 记录info类型的日志

func Panic

func Panic(msg string, kvs ...interface{})

Panic 记录panic类型的日志

func Warning

func Warning(msg string, kvs ...interface{})

Warning 记录warning类型的日志

Types

type Zap

type Zap struct {
	Log   *zap.Logger        // 日志对象
	Sugar *zap.SugaredLogger // sugar日志对象
	// contains filtered or unexported fields
}

Zap zap日志核心对象

func New

func New(config ZapConfig) *Zap

New 创建zap实例

func NewDebug added in v0.2.0

func NewDebug() *Zap

NewDebug 创建debug环境下的日志

func NewProduct added in v0.2.0

func NewProduct() *Zap

NewProduct 创建生产环境下的日志

func (*Zap) Debug

func (z *Zap) Debug(msg string, kvs ...interface{})

Debug 记录debug类型的日志

func (*Zap) Error

func (z *Zap) Error(msg string, kvs ...interface{})

Error 记录error类型的日志

func (*Zap) Fatal

func (z *Zap) Fatal(msg string, kvs ...interface{})

Fatal 记录fatal类型的日志

func (*Zap) Info

func (z *Zap) Info(msg string, kvs ...interface{})

Info 记录info类型的日志

func (*Zap) Panic

func (z *Zap) Panic(msg string, kvs ...interface{})

Panic 记录panic类型的日志

func (*Zap) Warning

func (z *Zap) Warning(msg string, kvs ...interface{})

Warning 记录warning类型的日志

type ZapConfig

type ZapConfig struct {
	Debug        bool   // 是否为debug模式
	OpenJsonLog  bool   // 是否开启json日志格式
	OpenGlobal   bool   // 是否开启全局日志
	OpenFileName bool   // 是否输出文件名和行号
	LogFilePath  string // 日志路径
	MaxSize      uint   // 日志最大保存多少M
	MaxBackups   uint   // 日志保留多少个备份
	MaxAge       uint   // 最多保留多少个日志
	Compress     bool   // 是否压缩
}

ZapConfig zap日志配置核心对象

Directories

Path Synopsis
examples
z01_hello command
z02_hello command

Jump to

Keyboard shortcuts

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