logger

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 8 Imported by: 0

README

logger

介绍

封装zap和lumberjack,生产易用,可使用仓库分装的logger 也可使用原生的zap

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLoggerConfig = &LoggerConfig{
		Level:    "info",
		TextMode: true,
		Console:  true,
	}
)

Functions

func GenRandomID

func GenRandomID(length int) (string, error)

生成安全的随机ID

func InitLogger

func InitLogger(conf *LoggerConfig) (err error)

InitLogger 初始化Logger

Types

type Field

type Field = zap.Field

func Any

func Any(key string, value interface{}) Field

func Bool

func Bool(key string, val bool) Field

func ByteString

func ByteString(key string, val []byte) Field

func Duration

func Duration(key string, val time.Duration) Field

func Float32

func Float32(key string, val float32) Field

func Float64

func Float64(key string, val float64) Field

func Int

func Int(key string, val int) Field

func Int32

func Int32(key string, val int32) Field

func Int64

func Int64(key string, val int64) Field

func String

func String(key string, val string) Field

func Time

func Time(key string, val time.Time) Field

func Uintptr

func Uintptr(key string, val uintptr) Field

type Logger

type Logger struct {
	*zap.Logger
}

func AddOperationID

func AddOperationID(l *Logger, idname string) *Logger

func L

func L() *Logger

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...Field)

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...Field)

func (*Logger) Error

func (l *Logger) Error(err error, fields ...Field)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...Field)

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...Field)

func (*Logger) Panic

func (l *Logger) Panic(msg error, fields ...Field)

func (*Logger) Sync

func (l *Logger) Sync() error

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...Field)

func (*Logger) With

func (l *Logger) With(fields ...Field) *Logger

type LoggerConfig

type LoggerConfig struct {
	Level      string `yaml:"level" json:"level"`             // debug, info, warn, error, dpanic, panic, fatal
	TextMode   bool   `yaml:"text_mode" json:"text_mode"`     // 是否以文本格式输出日志,默认为json格式输出
	Console    bool   `yaml:"console" json:"console"`         // 是否输出到终端,在未指定日志文件名,默认输出到终端
	Path       string `yaml:"path" json:"path"`               // 日志文件存放路径
	MaxSize    int    `yaml:"max_size" json:"max_size"`       // megabytes
	MaxBackups int    `yaml:"max_backups" json:"max_backups"` // 保留旧文件的最大个数
	MaxAge     int    `yaml:"max_age" json:"max_age"`         // 天数
	Compress   bool   `yaml:"compress" json:"compress"`       // 是否压缩/归档旧文件
}

Jump to

Keyboard shortcuts

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