logger

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, log ILogger) context.Context

Types

type ILogger

type ILogger interface {
	Debug(v ...interface{})
	Info(v ...interface{})
	Warning(v ...interface{})
	Error(v ...interface{})
	Critical(v ...interface{})
	Write(b []byte) (int, error)
}
var Log ILogger = &logger{}

func FromContext

func FromContext(ctx context.Context) ILogger

func New

func New(writer io.Writer, logLevel LogLevel, formatType LogFormatType, timeFmtTyp TimeFormatType) ILogger

type LogFormatType

type LogFormatType string
const (
	// FormatShort time:{{.Time}}\tlevel:{{.Level}}\tmessage:{{.Message}}\n
	FormatShort LogFormatType = "time:{{.Time}}\tlevel:{{.Level}}\tmessage:{{.Message}}\n"
	// FormatStandard time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tmessage:{{.Message}}\n
	FormatStandard LogFormatType = "time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tmessage:{{.Message}}\n"
	// FormatLong time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tfuncname:{{.Funcname}}\tmessage:{{.Message}}\n
	FormatLong LogFormatType = "time:{{.Time}}\tlevel:{{.Level}}\tfilename:{{.Filename}}:{{.LineNumber}}\tfuncname:{{.Funcname}}\tmessage:{{.Message}}\n"
)

func ConvertLogFmt

func ConvertLogFmt(fmt string) LogFormatType

func (LogFormatType) String

func (f LogFormatType) String() string

type LogLevel

type LogLevel int
const (
	Critical LogLevel = iota
	Error
	Warn
	Info
	Debug
)

func Convert

func Convert(level string) LogLevel

func (LogLevel) String

func (l LogLevel) String() string

type LogTemplate

type LogTemplate struct {
	Time       string
	Funcname   string
	Filename   string
	Level      string
	Goroutine  string
	LineNumber string
	Message    string
}

type LoggerKey

type LoggerKey struct{}

type TimeFormatType

type TimeFormatType string
const (
	// FormatDate 2006/01/02
	FormatDate TimeFormatType = "2006/01/02"
	// FormatDatetime 2006/01/02 15:04:05
	FormatDatetime TimeFormatType = "2006/01/02 15:04:05"
	// FormatMillisec 2006/01/02 15:04:05.000
	FormatMillisec TimeFormatType = "2006/01/02 15:04:05.000"
)

func ConvertTimeFmt

func ConvertTimeFmt(fmt string) TimeFormatType

func (TimeFormatType) String

func (t TimeFormatType) String() string

Jump to

Keyboard shortcuts

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