log

package
v1.0.7 Latest Latest
Warning

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

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

README

log

  • 支持控制台打印输出(默认开启)
  • 支持文件分片持久化输出(默认开启)
  • 支持ES日志上报(默认关闭)
func TestInit(t *testing.T) {
	err := Init(SetConf(Conf{
		CloseConsoleOutput: false,
		File: FileConf{
			CloseFileOutput: false,
			Name:            "test.log",
			MaxSize:         2,
			MaxAge:          30,
		},
		Es: EsConf{
			OpenEsOutput: true,
			Index:        "log",
			Addr:         "http://0.0.0.0:9200",
		},
	}))
	if err != nil {
		t.Error(err)
	}
	logrus.Info("123")
	return
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(opts ...Option) (*logrus.Logger, error)

Types

type Conf

type Conf struct {
	Level string `yaml:"level"`
	//控制台输出
	CloseConsoleOutput bool `yaml:"close_console_output"`
	//文件流输出
	File FileConf `yaml:"file"`
	//上报ES
	Es EsConf `yaml:"es"`
}

type EsConf

type EsConf struct {
	OpenEsOutput bool `yaml:"open_es_output"`
	//索引前缀
	Index string `yaml:"index"`
	//ES上报地址
	Addr string `yaml:"addr"`
}

type FileConf

type FileConf struct {
	CloseFileOutput bool `yaml:"close_file_output"`
	//日志文件名
	Name string `yaml:"name"`
	//日志文件的最大容量(mb)
	MaxSize int `yaml:"max_size"`
	//日志存放时间
	MaxAge int `yaml:"max_age"`
}

type HookEs

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

func NewHookEs

func NewHookEs(conf EsConf) (es *HookEs, err error)

func (*HookEs) Fire

func (es *HookEs) Fire(entry *logrus.Entry) error

func (*HookEs) Levels

func (es *HookEs) Levels() []logrus.Level

type Option

type Option func(l *_Log)

func SetConf

func SetConf(c Conf) Option

Jump to

Keyboard shortcuts

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