logs

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog

func AccessLog(msg string, fields ...zap.Field)

AccessLog

@Description: 封装debug级别的日志,用于打印accesslog日志。
@param msg
@param fields

func ErrorLog

func ErrorLog(msg string, fields ...zap.Field)

ErrorLog

@Description:  封装error级别的日志, 可以是Fatal,Panic
@param msg
@param fields

func GetLogFilePath

func GetLogFilePath(setting Setting) string

func GetLogger

func GetLogger() *zap.Logger

GetLogger

@Description: 获取logger实例 (业务中不使用debug,warn level来打印业务日志)
@return *zap.Logger

func InitLog

func InitLog(setting Setting)

InitLog 初始化全局logger 日志路径一般为:/home/service/${SERVICE_NAME}/logs

func LatencyLog

func LatencyLog(msg string, fields ...zap.Field)

LatencyLog

@Description:  封装warn级别的日志, 用于打印 服务耗时的日志(包含http和数据库)
@param msg
@param fields

Types

type KafkaLogger

type KafkaLogger struct{}

func (KafkaLogger) Print

func (k KafkaLogger) Print(v ...interface{})

func (KafkaLogger) Printf

func (k KafkaLogger) Printf(format string, v ...interface{})

func (KafkaLogger) Println

func (k KafkaLogger) Println(v ...interface{})

type MysqlLogger

type MysqlLogger struct {
	EnableNormal bool // 是否开始普通日志
}

要实现以下方法

type Interface interface {
	LogMode(LogLevel) Interface
	Info(context.Context, string, ...interface{})
	Warn(context.Context, string, ...interface{})
	Error(context.Context, string, ...interface{})
	Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
}

func (MysqlLogger) Error

func (d MysqlLogger) Error(ctx context.Context, s string, i ...interface{})

func (MysqlLogger) Info

func (d MysqlLogger) Info(ctx context.Context, s string, i ...interface{})

func (MysqlLogger) LogMode

func (d MysqlLogger) LogMode(level logger.LogLevel) logger.Interface

func (MysqlLogger) Trace

func (d MysqlLogger) Trace(
	ctx context.Context,
	begin time.Time,
	fc func() (sql string, rowsAffected int64), err error)

Trace

@Description: 记录mysql的日志
@receiver d 自定义 gorm日志
@param ctx
@param begin
@param fc
@param err

func (MysqlLogger) Warn

func (d MysqlLogger) Warn(ctx context.Context, s string, i ...interface{})

type Setting

type Setting struct {
	// RuntimeRootPath 根路径,默认是/home/service/
	RuntimeRootPath string `mapstructure:"runtime_root_path"`
	// Project 当前所在ip
	LocalIp string
	// Project 项目名,用于组成最终的日志路径
	Project string
	Module  string
	// 日志文件最多保留时长,天
	MaxRetentionDays int
	// 是否日志分级存储
	IsLevel bool
	// 是否标准输出到控制台
	StdOut bool
}

Jump to

Keyboard shortcuts

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