zdpgo_log

package module
v1.0.3 Latest Latest
Warning

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

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

README

zdpgo_zap

基于zap二次封装的日志库

版本历史

  • v0.1.0:2022年1月30日
  • v0.1.1:2022年1月30日
  • v0.2.0:2022年2月10日 新增日志备份功能
  • v0.2.1:2022年2月10日 新增自动创建日志目录功能
  • v0.2.2:2022年2月11日 将日志对象开放给外部使用
  • v0.2.3:2022年2月11日 bug修复
  • v1.0.0:2022年3月8日 优化日志方法
  • v1.0.1:2022年4月5日 优化代码结构
  • v1.0.2:2022年4月7日 移除没必要的第三方依赖
  • v1.0.3:2022年4月26日 优化:移除全局日志,优化日志创建方式

使用案例

基本使用
package main

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.0.3

type Config struct {
	Debug        bool   `env:"debug" yaml:"debug" json:"debug"`                            // 是否为debug模式
	OpenJsonLog  bool   `env:"open_json_log" yaml:"open_json_log" json:"open_json_log"`    // 是否开启json日志格式
	OpenFileName bool   `env:"open_file_name" yaml:"open_file_name" json:"open_file_name"` // 是否输出文件名和行号
	LogFilePath  string `env:"log_file_path" yaml:"log_file_path" json:"log_file_path"`    // 日志路径
	MaxSize      uint   `env:"max_size" yaml:"max_size" json:"max_size"`                   // 日志最大保存多少M
	MaxBackups   uint   `env:"max_backups" yaml:"max_backups" json:"max_backups"`          // 日志保留多少个备份
	MaxAge       uint   `env:"max_age" yaml:"max_age" json:"max_age"`                      // 最多保留多少天日志
	Compress     bool   `env:"compress" 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() *Log

New 创建zap实例

func NewWithConfig added in v1.0.3

func NewWithConfig(config Config) *Log

NewWithConfig 创建zap实例

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