log

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 9 Imported by: 0

README

日志库

  • 日志滚动,保存15天内的日志,每1小时(整点)分割一次日志(可配置)
  • 日志文件分级保存 debug, info, error
  • 可选是否输出日志到控制台
  • 支持输出打日志的文件文件行号

使用

只支持单例log


// 使用前必须先初始化
log.Init(&log.LogConfig{
	Level:   "info", // 日志级别
	Path:    ".runtime/logs", // 日志保存路径
	Name:    "api", // 日志文件名
	Console: true, // 是否把日志输出到控制台
	Caller: true, // 是否输出打日志的文件和行号,会影响性能
	MaxAge: time.Hour * 24 * 15, // 保存多久的日志,默认15天
	RotationTime: time.Hour, // 多久分割一次日志,默认一小时
    SplitLevel: true, // 是否把不同级别的日志打到不同文件,如果为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"})

godoc

API 文档

Documentation

Index

Constants

This section is empty.

Variables

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

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 Init

func Init(conf *LogConfig) error

Init 初始化日志库

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