zlog

package module
v1.0.1-0...-fd4976e Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2020 License: Apache-2.0 Imports: 13 Imported by: 2

README

go-zlog

日志插件, 用于输出日志到指定位置, 方便调试, 本库是对 logrus 进行了封装

日志所用到的库

logrus 日志

logrus-prefixed-formatter 日志格式化

使用方法

import "github.com/caryxiao/go-zlog"
func main() {
  zlog.SetOutput("/tmp/zlog.log")
  zlog.SetLevel(5)
  zlog.SetFormat("[%level%]: %time% - [%trace_id%] %msg%")
  zlog.Logger.Debug("test debug")
}

Documentation

Index

Constants

View Source
const (
	PanicLevel = logrus.PanicLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel = logrus.FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel = logrus.ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel = logrus.WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel = logrus.InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel = logrus.DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel = logrus.TraceLevel
)

Variables

View Source
var Logger = logrus.New()

Functions

func SetFormat

func SetFormat(format string)

设置格式化的格式

func SetLevel

func SetLevel(level interface{})

设置日志输出级别

func SetOutput

func SetOutput(writer interface{})

设置输出的位置

Types

type ColorScheme

type ColorScheme struct {
	InfoLevel  string
	WarnLevel  string
	ErrorLevel string
	FatalLevel string
	PanicLevel string
	DebugLevel string
	Timestamp  string
}

type TextFormatter

type TextFormatter struct {
	LogFormat       string
	TimestampFormat string

	QuoteCharacter string

	sync.Once
	// contains filtered or unexported fields
}

func (*TextFormatter) Format

func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)

func (*TextFormatter) SetColorScheme

func (f *TextFormatter) SetColorScheme(colorScheme *ColorScheme)

type TraceIdGenerate

type TraceIdGenerate struct {
	Prefix      string
	MoreEntropy bool
}

Jump to

Keyboard shortcuts

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