loggo

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 7 Imported by: 3

README

loggo

go 一个日志接口
  • 提供了一个日志接口

type Log interface {
	Debug(v ...interface{})
	Debugf(msg string, v ...interface{})
	Info(v ...interface{})
	Infof(msg string, v ...interface{})
	Warn(v ...interface{})
	Warnf(msg string, v ...interface{})
	Error(v ...interface{})
	Errorf(msg string, v ...interface{})
	Panic(v ...interface{})
	Panicf(msg string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(msg string, v ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
}
  • 提供了 zap 和 logrus 两个实现,默认为 zap 实现,用户也可以自己实现并通过 SetLog 替换默认实现

使用示例:

func ConfigLog() {
	output := &lumberjack.Logger{
		Filename: conf.CFG.LogFile,

		// default 100
		MaxSize: 300, // megabytes

		MaxBackups: 60,
		MaxAge:     60,   //days
		Compress:   true, // disabled by default
	}
	loggo.NewZapLog(conf.CFG.LogLevel, output)
	loggo.Info("loggo configuration done.")
}

自定义 log, 只需实现 Log 接口

package main

import (
    "fmt"
    "github.com/rickiey/loggo"
)

func main() {
    loggo.SetLog(new(flog))
    loggo.Info("loggo ...")
}

type flog struct{}
func (l *flog) Print(v ...interface{}) { fmt.Println(v...) }
func (l *flog) Println(v ...interface{}) { fmt.Println(v...) }

func (l *flog) Debug(v ...interface{}) {fmt.Println(v...)}

func (l *flog) Debugf(msg string, v ...interface{}) {fmt.Printf(msg, v...)}

func (l *flog) Info(v ...interface{}) {fmt.Println(v...)}

func (l *flog) Infof(msg string, v ...interface{}) {fmt.Printf(msg, v...)}

func (l *flog) Warn(v ...interface{}) {fmt.Println(v...)}

func (l *flog) Warnf(msg string, v ...interface{}) {fmt.Printf(msg, v...)}

func (l *flog) Error(v ...interface{}) {fmt.Println(v...)}

func (l *flog) Errorf(msg string, v ...interface{}) {fmt.Printf(msg, v...)}

func (l *flog) Panic(v ...interface{}) {fmt.Println(v...)}

func (l *flog) Panicf(msg string, v ...interface{}) {fmt.Printf(msg, v...)}
func (l *flog) Fatal(v ...interface{}) { fmt.Println(v...) }
func (l *flog) Fatalf(msg string, v ...interface{}) { fmt.Printf(msg, v...) }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

func Debugf

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

func Error

func Error(v ...interface{})

func Errorf

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

func Fatal added in v0.3.0

func Fatal(v ...interface{})

func Fatalf added in v0.3.0

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

func Info

func Info(v ...interface{})

func Infof

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

func Panic

func Panic(v ...interface{})

func Panicf

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

func ParseZapLevel

func ParseZapLevel(text string) zapcore.Level

func SetLog

func SetLog(l Log)

func Warn

func Warn(v ...interface{})

func Warnf

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

Types

type Log

type Log interface {
	Debug(v ...interface{})
	Debugf(msg string, v ...interface{})
	Info(v ...interface{})
	Infof(msg string, v ...interface{})
	Warn(v ...interface{})
	Warnf(msg string, v ...interface{})
	Error(v ...interface{})
	Errorf(msg string, v ...interface{})
	Panic(v ...interface{})
	Panicf(msg string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(msg string, v ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
}
var Logger Log

func NewLogrusLog

func NewLogrusLog(level string, output io.Writer) Log

func NewZapLog

func NewZapLog(level string, output io.Writer) Log

func NewZerolog added in v0.5.0

func NewZerolog(level string, output io.Writer) Log

type ZeloLog added in v0.5.0

type ZeloLog struct {
	// contains filtered or unexported fields
}

func (*ZeloLog) Debug added in v0.5.0

func (z *ZeloLog) Debug(v ...interface{})

func (*ZeloLog) Debugf added in v0.5.0

func (z *ZeloLog) Debugf(msg string, v ...interface{})

func (*ZeloLog) Error added in v0.5.0

func (z *ZeloLog) Error(v ...interface{})

func (*ZeloLog) Errorf added in v0.5.0

func (z *ZeloLog) Errorf(msg string, v ...interface{})

func (*ZeloLog) Fatal added in v0.5.0

func (z *ZeloLog) Fatal(v ...interface{})

func (*ZeloLog) Fatalf added in v0.5.0

func (z *ZeloLog) Fatalf(msg string, v ...interface{})

func (*ZeloLog) Info added in v0.5.0

func (z *ZeloLog) Info(v ...interface{})

func (*ZeloLog) Infof added in v0.5.0

func (z *ZeloLog) Infof(msg string, v ...interface{})

func (*ZeloLog) Panic added in v0.5.0

func (z *ZeloLog) Panic(v ...interface{})

func (*ZeloLog) Panicf added in v0.5.0

func (z *ZeloLog) Panicf(msg string, v ...interface{})

func (*ZeloLog) Print added in v0.5.0

func (z *ZeloLog) Print(v ...interface{})

func (*ZeloLog) Println added in v0.5.0

func (z *ZeloLog) Println(v ...interface{})

func (*ZeloLog) Warn added in v0.5.0

func (z *ZeloLog) Warn(v ...interface{})

func (ZeloLog) Warnf added in v0.5.0

func (z ZeloLog) Warnf(msg string, v ...interface{})

Jump to

Keyboard shortcuts

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