log

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

日志库

采用 zap + file-rotatelogs 实现的日志库

使用


import "gitee.com/novanest/toolkit/log"

// 使用前必须先初始化 初始化log 有两种方式
// 第一种使用方式
log.InitDefault(nil) // 使用默认配置初始化
// // 第二种使用方式
log.InitDefault(func (conf *log.LogConfig{
	Level:   "info", // 日志级别 默认info
	Path:    ".runtime/logs", // 日志保存路径 默认 ./log
	Name:    "api", // 日志文件名 默认工程名+年月日
	Console: true, // 是否把日志输出到控制台 默认false
	Caller: true, // 是否输出打日志的文件和行号,会影响性能 默认false
	MaxAge: time.Hour * 24 * 15, // 保存多久的日志,默认7天
	RotationTime: time.Hour, // 多久分割一次日志,默认一天
    SplitLevel: true, // 是否把不同级别的日志打到不同文件,如果为false 则所有级别日志打到同一个文件 默认false
}))



log.Debug("is debug log")
log.Info("is info log")
log.Warn("is warn log")
log.Error("is error log")
log.Panic("is panic log")

log.Debugf("is debug log %s %d %v", "string", 123, map[string]string{"test": "hello"})
log.Infof("is info log %s %d %v", "string", 123, map[string]string{"test": "hello"})
log.Warnf("is warn log %s %d %v", "string", 123, map[string]string{"test": "hello"})
log.Errorf("is error log %s %d %v", "string", 123, map[string]string{"test": "hello"})
log.Fatalf("is fatal log %s %d %v", "string", 123, map[string]string{"test": "hello"})
log.Panicf("is panic log %s %d %v", "string", 123, map[string]string{"test": "hello"})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SugaredLogger = defaultLogger.Sugar()
	Logger        = defaultLogger
)

Functions

func Debug

func Debug(v ...interface{})

Debug 打日志

func Debugf

func Debugf(s string, v ...interface{})

Debugf 格式化日志

func Error

func Error(v ...interface{})

Error 打日志

func Errorf

func Errorf(s string, v ...interface{})

Errorf 格式化日志

func Fatalf

func Fatalf(s string, v ...interface{})

Fatalf 格式化日志

func Info

func Info(v ...interface{})

Info 打日志

func Infof

func Infof(s string, v ...interface{})

Infof 格式化日志

func InitDefault

func InitDefault(fn func(conf *LogConfig)) error

InitDefault 初始化日志库

func Panic

func Panic(v ...interface{})

Panic 打日志

func Panicf

func Panicf(s string, v ...interface{})

Panicf 格式化日志

func Warn

func Warn(v ...interface{})

Warn 打日志

func Warnf

func Warnf(s string, v ...interface{})

Warnf 格式化日志

Types

type LogConfig

type LogConfig struct {
	Level        string        // 日志级别
	Path         string        // 路径
	Name         string        // 文件名称
	Console      bool          // 是否输出到控制台
	MaxAge       time.Duration // 保存多久的日志,默认15天
	RotationTime time.Duration // 多久分割一次日志
	Caller       bool          // 是否打印文件行号
	SplitLevel   bool          // 是否把不同级别的日志打到不同文件
}

LogConfig 日志配置

Jump to

Keyboard shortcuts

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