zdpgo_log

package module
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 8 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.3.1 2022/4/26 优化:移除全局日志,优化日志创建方式
  • v1.3.2 2022/5/10 新增:Debug日志可以只展示在控制台但是不写入日志文件
  • v1.3.3 2022/5/11 BUG修复:解决某些情况下Debug方法不能用
  • v1.3.4 2022/5/16 新增:根据debug值和日志路径创建日志对象

使用案例

基本使用
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模式
	LogLevel      string `env:"log_level" yaml:"log_level" json:"log_level"`                   // 日志级别
	IsWriteDebug  bool   `env:"is_write_debug" yaml:"is_write_debug" json:"is_write_debug"`    // 是否将debug日志写入文件
	IsShowConsole bool   `env:"is_show_console" yaml:"is_show_console" json:"is_show_console"` // 是否在控制台展示
	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 {

	// 日志方法
	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实例

func NewWithDebug added in v1.3.4

func NewWithDebug(debug bool, logFilePath string) *Log

NewWithDebug 根据debug值和日志路径创建日志对象

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