logz

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

README

# 日志配置
Log:
  # Default:日志方式。 console:控制台日志打印,file:文件日志存储,kafka:写入kafka队列,需要配置elk相关组件
  # 支持多个同时存在,多个以,隔开:console,file,kafka (配置file和kafka时需要配置参数信息)
  Default: "console"
  Level: "info" #  debug info warn error 
  Encoder: "json" # plain json
  File:
    FilePath: "storage/logs/logs.log"
    MaxSize: 64
    MaxBackup: 10
    MaxAge: 30
    Compress: false
  Kafka:
    Host:
      - "127.0.0.1:9092"
    topic: "my-topic"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *zap.Logger

Logger 全局 Logger 对象

Functions

func Debug

func Debug(moduleName string, fields ...zap.Field)

Debug 调试日志,详尽的程序日志

logger.Debug("Database", zap.String("sql", sql))

func DebugAny

func DebugAny(msg ...any)

func DebugJSON

func DebugJSON(moduleName, name string, value interface{})

DebugJSON 记录对象类型的 debug 日志,使用 json.Marshal 进行编码。调用示例:

logger.DebugJSON("Auth", "读取登录用户", auth.CurrentUser())

func Dump

func Dump(value interface{}, msg ...string)

func Error

func Error(moduleName string, fields ...zap.Field)

Error 错误时记录,不应该中断程序,查看日志时重点关注

func ErrorAny

func ErrorAny(msg ...any)

func ErrorJSON

func ErrorJSON(moduleName, name string, value interface{})

func Fatal

func Fatal(moduleName string, fields ...zap.Field)

Fatal 级别同 Error(), 写完 log 后调用 os.Exit(1) 退出程序

func FatalAny

func FatalAny(msg ...any)

func FatalJSON

func FatalJSON(moduleName, name string, value interface{})

func GinLogger added in v0.0.2

func GinLogger() gin.HandlerFunc

func GinRecovery added in v0.0.2

func GinRecovery(stack bool) gin.HandlerFunc

func Info

func Info(moduleName string, fields ...zap.Field)

Info 告知类日志

func InfoAny

func InfoAny(msg ...any)

func InfoJSON

func InfoJSON(moduleName, name string, value interface{})

func InitLog

func InitLog(c Config)

func LogErrIf

func LogErrIf(err error)

LogErrIf 当 err != nil 时记录 error 等级的日志

func LogInfoIf

func LogInfoIf(err error)

LogInfoIf 当 err != nil 时记录 info 等级的日志

func LogWarnIf

func LogWarnIf(err error)

LogWarnIf 当 err != nil 时记录 warning 等级的日志

func Warn

func Warn(moduleName string, fields ...zap.Field)

Warn 警告类

func WarnAny

func WarnAny(msg ...any)

func WarnJSON

func WarnJSON(moduleName, name string, value interface{})

Types

type Config

type Config struct {
	Default string
	Level   string
	Encoder string
	File    File
	Kafka   Kafka
}

type File

type File struct {
	FilePath  string
	MaxSize   int
	MaxBackup int
	MaxAge    int
	Compress  bool
}

type GormWriter

type GormWriter struct {
}

func NewGormWriter

func NewGormWriter() *GormWriter

func (*GormWriter) Printf

func (w *GormWriter) Printf(key string, data ...interface{})

Printf 实现打印日志接口

type Kafka

type Kafka struct {
	Host  []string
	Topic string
}

type KafkaLogWriter

type KafkaLogWriter struct {
	Pusher *kq.Pusher
}

func (*KafkaLogWriter) Sync

func (w *KafkaLogWriter) Sync() error

func (*KafkaLogWriter) Write

func (w *KafkaLogWriter) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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