logger

package module
v0.0.0-...-8259bb9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 12 Imported by: 3

README

logger

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPrefixSep = "|"
View Source
var DefaultTimeLayout = "2006-01-02 15:04:05"
View Source
var DefaultTimePrefix = &TimePrefix{}
View Source
var PrefixID = PrefixFunc(func(l *Logger) string {
	return l.ID
})
View Source
var SpaceSeparatedFormatter = SeparatedFormatter(",")

Functions

func Debug

func Debug(s string)

func EnableDevelopmengLoggers

func EnableDevelopmengLoggers()

func Error

func Error(s string)

func Factories

func Factories() []string

Factories returns a sorted list of the names of the registered factories.

func Fatal

func Fatal(s string)

func Info

func Info(s string)

func InitLogger

func InitLogger(l *Logger, option string, loader func(v interface{}) error) error

func Panic

func Panic(s string)

func Print

func Print(s string)

func Register

func Register(name string, f Factory)

Register makes a driver creator available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

func RegisterAbsoluteFileFactory

func RegisterAbsoluteFileFactory()

func RegisterBuiltinFactory

func RegisterBuiltinFactory()

func Reopen

func Reopen(w ...Writer)

func ReopenBuiltinLoggers

func ReopenBuiltinLoggers()

func ResetBuiltinLoggers

func ResetBuiltinLoggers()

func Trace

func Trace(s string)

func UnregisterAll

func UnregisterAll()

UnregisterAll unregister all driver

func Warning

func Warning(s string)

Types

type Factory

type Factory func(u *url.URL, loader func(v interface{}) error) (Option, error)

type FileWriter

type FileWriter struct {
	Path string
	Mode os.FileMode
	// contains filtered or unexported fields
}

func NewFileWriter

func NewFileWriter(path string, mode os.FileMode) *FileWriter

func (*FileWriter) Close

func (o *FileWriter) Close() error

func (*FileWriter) Open

func (o *FileWriter) Open() error

func (*FileWriter) Reopen

func (o *FileWriter) Reopen() error

func (*FileWriter) WriteLine

func (o *FileWriter) WriteLine(s string) error

type FixedPrefix

type FixedPrefix string

func (FixedPrefix) NewPrefix

func (p FixedPrefix) NewPrefix(*Logger) string

type FormatLogger

type FormatLogger struct {
	Logger    *Logger
	Formatter Formatter
}

func (*FormatLogger) FormatAndLog

func (l *FormatLogger) FormatAndLog(log Log)

func (*FormatLogger) SetFormatter

func (l *FormatLogger) SetFormatter(f Formatter) *FormatLogger

type Formatter

type Formatter interface {
	Format(Log) string
}
var DefaultFormatter Formatter = SpaceSeparatedFormatter

type IOWriter

type IOWriter struct {
	Writer io.Writer
}

func (*IOWriter) Close

func (o *IOWriter) Close() error

func (*IOWriter) Open

func (o *IOWriter) Open() error

func (*IOWriter) Reopen

func (o *IOWriter) Reopen() error

func (*IOWriter) WriteLine

func (o *IOWriter) WriteLine(s string) error

type Log

type Log interface {
	DefaultLogFields() []interface{}
	LogFields() map[string]interface{}
}

type LogFields

type LogFields []string

func NewLogFields

func NewLogFields(fields ...string) *LogFields

func (*LogFields) NewLog

func (f *LogFields) NewLog() *PlainLog

type Logger

type Logger struct {
	Writer
	ID      string
	Prefixs []Prefix
}
var DebugLogger *Logger
var ErrorLogger *Logger
var FatalLogger *Logger
var InfoLogger *Logger
var PanicLogger *Logger
var PrintLogger *Logger
var TraceLogger *Logger
var WarningLogger *Logger

func GetBuiltinLogger

func GetBuiltinLogger(name string) *Logger

GetBuiltinLogger get builtin logger by name. Return nil if logger not found.

func NewLogger

func NewLogger() *Logger

func (*Logger) AppendPrefixs

func (l *Logger) AppendPrefixs(p ...Prefix) *Logger

func (*Logger) Clone

func (l *Logger) Clone() *Logger

func (*Logger) FormatLogger

func (l *Logger) FormatLogger() *FormatLogger

func (*Logger) Log

func (l *Logger) Log(s string)

func (*Logger) ReplaceWriter

func (l *Logger) ReplaceWriter(w Writer) error

func (*Logger) SetID

func (l *Logger) SetID(id string) *Logger

func (*Logger) SetPrefixs

func (l *Logger) SetPrefixs(p ...Prefix) *Logger

func (*Logger) SetWriter

func (l *Logger) SetWriter(w Writer) *Logger

func (*Logger) SubLogger

func (l *Logger) SubLogger() *Logger

type Option

type Option interface {
	ApplyTo(*Logger) error
}

type OptionFunc

type OptionFunc func(*Logger) error

func (OptionFunc) ApplyTo

func (o OptionFunc) ApplyTo(l *Logger) error

type PlainLog

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

func NewPlainLog

func NewPlainLog() *PlainLog

func (*PlainLog) DefaultLogFields

func (l *PlainLog) DefaultLogFields() []interface{}

func (*PlainLog) LogFields

func (l *PlainLog) LogFields() map[string]interface{}

func (*PlainLog) WithField

func (l *PlainLog) WithField(name string, value interface{}) *PlainLog

type Prefix

type Prefix interface {
	NewPrefix(*Logger) string
}

type PrefixFunc

type PrefixFunc func(*Logger) string

func (PrefixFunc) NewPrefix

func (f PrefixFunc) NewPrefix(l *Logger) string

type ReplacementFormater

type ReplacementFormater string

func (ReplacementFormater) Format

func (f ReplacementFormater) Format(l Log) string

type SeparatedFormatter

type SeparatedFormatter string

func (SeparatedFormatter) Format

func (f SeparatedFormatter) Format(l Log) string

type TimePrefix

type TimePrefix struct {
	Layout string
}

func (*TimePrefix) NewPrefix

func (p *TimePrefix) NewPrefix(*Logger) string

type Writer

type Writer interface {
	Open() error
	Close() error
	Reopen() error
	WriteLine(s string) error
}
var Null Writer = &IOWriter{
	Writer: ioutil.Discard,
}
var Stderr Writer = &IOWriter{
	Writer: os.Stderr,
}
var Stdout Writer = &IOWriter{
	Writer: os.Stdout,
}

Jump to

Keyboard shortcuts

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