zdpgo_log

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 7 Imported by: 15

README

zdpgo_zap

基于zap二次封装的日志库

版本历史

  • 版本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日 将日志对象开放给外部使用
  • 版本0.2.3:2022年2月11日 bug修复
  • 版本1.0.0:2022年3月8日 优化日志方法
  • 版本1.0.1:2022年4月5日 优化代码结构
  • 版本1.0.2:2022年4月7日 移除没必要的第三方依赖

使用案例

基本使用
package main

import (
	"github.com/zhangdapeng520/zdpgo_log"
)

func main() {
	l := zdpgo_log.New(zdpgo_log.Config{
		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")

	// 全局日志
	zdpgo_log.S().Debug("全局的debug日志全局的debug日志全局的debug日志全局的debug日志全局的debug日志全局的debug日志全局的debug日志全局的debug日志全局的debug日志。。。。")
	zdpgo_log.S().Info("全局的info日志。。。。")
	zdpgo_log.S().Warn("全局的warning日志。。。")
	zdpgo_log.S().Error("全局的error日志。。。。")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug   func(msg string, args ...interface{})
	Info    func(msg string, args ...interface{})
	Warning func(msg string, args ...interface{})
	Error   func(msg string, args ...interface{})
	Panic   func(msg string, args ...interface{})
	Fatal   func(msg string, args ...interface{})

	// S 全局的日志对象
	S = zap.S
)

全局日志

Functions

This section is empty.

Types

type Config added in v1.0.3

type Config struct {
	Debug        bool   `yaml:"debug" json:"debug"`                   // 是否为debug模式
	OpenJsonLog  bool   `yaml:"open_json_log" json:"open_json_log"`   // 是否开启json日志格式
	OpenGlobal   bool   `yaml:"open_global" json:"open_global"`       // 是否开启全局日志
	OpenFileName bool   `yaml:"open_file_name" json:"open_file_name"` // 是否输出文件名和行号
	LogFilePath  string `yaml:"log_file_path" json:"log_file_path"`   // 日志路径
	MaxSize      uint   `yaml:"max_size" json:"max_size"`             // 日志最大保存多少M
	MaxBackups   uint   `yaml:"max_backups" json:"max_backups"`       // 日志保留多少个备份
	MaxAge       uint   `yaml:"max_age" json:"max_age"`               // 最多保留多少个日志
	Compress     bool   `yaml:"compress" json:"compress"`             // 是否压缩
}

Config zap日志配置核心对象

type Log

type Log struct {
	Log   *zap.Logger        // 日志对象
	Sugar *zap.SugaredLogger // sugar日志对象

	// 日志方法
	Debug   func(msg string, args ...interface{})
	Info    func(msg string, args ...interface{})
	Warning func(msg string, args ...interface{})
	Error   func(msg string, args ...interface{})
	Panic   func(msg string, args ...interface{})
	Fatal   func(msg string, args ...interface{})
	// contains filtered or unexported fields
}

Log 日志核心对象

func New

func New(config Config) *Log

New 创建zap实例

func NewDebug added in v1.3.0

func NewDebug() *Log

NewDebug 创建debug环境下的日志

func NewProduct added in v1.3.0

func NewProduct() *Log

NewProduct 创建生产环境下的日志

Directories

Path Synopsis
examples
z01_hello command
libs
atomic/internal/gen-atomicint command
gen-atomicint generates an atomic wrapper around an integer type.
gen-atomicint generates an atomic wrapper around an integer type.
atomic/internal/gen-atomicwrapper command
gen-atomicwrapper generates wrapper types around other atomic types.
gen-atomicwrapper generates wrapper types around other atomic types.
multierr
Package multierr allows combining one or more errors together.
Package multierr allows combining one or more errors together.
zap
Package zap provides fast, structured, leveled logging.
Package zap provides fast, structured, leveled logging.
zap/zapgrpc
Package zapgrpc provides a logger that is compatible with grpclog.
Package zapgrpc provides a logger that is compatible with grpclog.
zap/zaptest/observer
Package observer provides a zapcore.Core that keeps an in-memory, encoding-agnostic representation of log entries.
Package observer provides a zapcore.Core that keeps an in-memory, encoding-agnostic representation of log entries.

Jump to

Keyboard shortcuts

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