logger

package
v0.0.0-...-f19f24e Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ConsoleBlack   = "\x1b[30m"
	ConsoleRed     = "\x1b[31m"
	ConsoleGreen   = "\x1b[32m"
	ConsoleYellow  = "\x1b[33m"
	ConsoleBlue    = "\x1b[34m"
	ConsoleMagenta = "\x1b[35m"
	ConsoleCyan    = "\x1b[36m"
	ConsoleWhite   = "\x1b[37m"

	ConsoleReset = "\x1b[0m"
)
View Source
const (
	LevelAbort = iota
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug

	LoggerConsole = "console"
	LoggerFile    = "file"

	LogRotateNo    = 0
	LogRotateLines = 1
	LogRotateDaily = 2
	LogRotateHour  = 3
)
View Source
const TimeFormatter = "2006-01-02 15:04:05.000"

Variables

This section is empty.

Functions

func Abort

func Abort(f string, v ...interface{})

func ColorText

func ColorText(text, color string) string

func Debug

func Debug(f string, v ...interface{})

func Error

func Error(f string, v ...interface{})

func Info

func Info(f string, v ...interface{})

func InitLogger

func InitLogger(level string, opts ...LoggerOpts) error

func RegisterLoggerWriter

func RegisterLoggerWriter(name string, loggerCreateFunc LoggerWriterCreateFunc)

func SetLevel

func SetLevel(level int)

func Warn

func Warn(f string, v ...interface{})

Types

type ConsoleWriter

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

func (*ConsoleWriter) Colorful

func (cw *ConsoleWriter) Colorful() bool

func (*ConsoleWriter) Flush

func (cw *ConsoleWriter) Flush()

func (*ConsoleWriter) MatchPrefix

func (cw *ConsoleWriter) MatchPrefix(prefix string) bool

func (*ConsoleWriter) Write

func (cw *ConsoleWriter) Write(b []byte) (int, error)

type FileWriter

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

func (*FileWriter) Colorful

func (fw *FileWriter) Colorful() bool

func (*FileWriter) Flush

func (fw *FileWriter) Flush()

func (*FileWriter) MatchPrefix

func (fw *FileWriter) MatchPrefix(prefix string) bool

func (*FileWriter) Write

func (fw *FileWriter) Write(b []byte) (int, error)

type Logger

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

func GetLogger

func GetLogger(prefix ...string) *Logger

func NewLogger

func NewLogger(prefix, level string, async bool) *Logger

func (*Logger) Abort

func (l *Logger) Abort(f string, v ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(f string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(f string, v ...interface{})

func (*Logger) Info

func (l *Logger) Info(f string, v ...interface{})

func (*Logger) SetFormatter

func (l *Logger) SetFormatter(formatterFunc LoggerFormatterFunc)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

func (*Logger) Warn

func (l *Logger) Warn(f string, v ...interface{})

type LoggerFormatter

type LoggerFormatter interface {
	Format(colorful bool) string
}

type LoggerFormatterFunc

type LoggerFormatterFunc func(msg *LoggerMsg, colorful bool) string

formatter 这个事情貌似不是很合理

type LoggerMsg

type LoggerMsg struct {
	Prefix string
	Level  int
	Time   time.Time
	Caller struct {
		FileName string
		Line     int
	}
	Msg string
	// contains filtered or unexported fields
}

func (*LoggerMsg) Format

func (lmsg *LoggerMsg) Format(colorful bool) string

type LoggerOpts

type LoggerOpts struct {
	Type     string   `json:"type"`
	Prefixs  []string `json:"prefix"`
	FileName string   `json:"fileName"`
	Rotate   int      `json:"rotate,omitempty"`
	MaxLines int      `json:"maxLines,omitempty"`
	MaxSize  int64    `json:"maxSize,omitempty"`
}

type LoggerWriter

type LoggerWriter interface {
	MatchPrefix(prefix string) bool
	Colorful() bool
	Write([]byte) (int, error)
	Flush()
}

func NewConsoleWriter

func NewConsoleWriter(opts LoggerOpts) LoggerWriter

func NewFileWriter

func NewFileWriter(opts LoggerOpts) LoggerWriter

type LoggerWriterCreateFunc

type LoggerWriterCreateFunc func(opts LoggerOpts) LoggerWriter

Jump to

Keyboard shortcuts

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