log4g

package module
v0.0.0-...-43adc12 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: MIT Imports: 5 Imported by: 0

README

Log4g是什么?

Log4g是一个基于logruslumberjack的日志工具,保留原有logrus的扩展功能,并支持日志输出配置。

至于为什么基于logrus,别问!问就是用star最多的库。

Log4g特性

  1. 得益于lumberjack,日志文件可以自动进行切割输出。理论上支持所有lumberjack配置
  2. 采用日志文件输出时,不会在控制台打印日志,如果需要,可以通过Hook方式扩展控制台与文件同时输出。
  3. 使用TOML作为配置文件
  4. 不同日志级别分文件输出
  5. 同一日志级别可以输出到任意多个文件中

配置Log4g

[[appender]]
filename = "/Users/xxxx/Desktop/logs/info.log"
maxSize = 1
maxAge = 1
maxBackups = 5
localTime = false
compress = false
minLevel = "INFO"
maxLevel = "INFO"

更多配置可参考lumberjack

如果希望在控制台输出,可以删掉或者修改appender配置。对于没有appender配置的日志级别,Log4g会使用logrus的默认输出。

使用Log4g

package main

import log "github.com/jptangchina/log4g"

func main() {
  log.Info("Test info output")
}

TODO

  1. 测试文件还没写,还没仔细进行全面的测试,哈哈

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugln

func Debugln(args ...interface{})

func Degbugf

func Degbugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Fatalln

func Fatalln(args ...interface{})

func GetLogger

func GetLogger(level logrus.Level) *logrus.Logger

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func Panicln

func Panicln(args ...interface{})

func Trace

func Trace(args ...interface{})

func Tracef

func Tracef(format string, args ...interface{})

func Traceln

func Traceln(args ...interface{})

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

func Warnln

func Warnln(args ...interface{})

Types

type Appender

type Appender struct {
	Filename   string
	MaxSize    int
	MaxAge     int
	MaxBackups int
	LocalTime  bool
	Compress   bool
	MaxLevel   string
	MinLevel   string
}

type Appenders

type Appenders struct {
	Appender []Appender
}

func InitAppenders

func InitAppenders() (*Appenders, error)

type Log4gHook

type Log4gHook struct {
	Writer *lumberjack.Logger
	Level  []logrus.Level
}

func (*Log4gHook) Fire

func (l *Log4gHook) Fire(entry *logrus.Entry) error

func (*Log4gHook) Levels

func (l *Log4gHook) Levels() []logrus.Level

Jump to

Keyboard shortcuts

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