log

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = New(DefaultOptions)
View Source
var DefaultOptions = &Options{
	Level: DEBUG,
}
View Source
var New = func(opts *Options) *logger {
	out := os.Stdout
	if opts.Path != "" {
		logFile, err := os.OpenFile(opts.Path, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
		if err != nil {
			fmt.Println("open file, ERROR : ", err)
		}
		out = logFile
	}

	return &logger{
		log.New(out, fmt.Sprintf("%s[DRACARYS]%s", dracarys, reset), log.LstdFlags|log.Lshortfile),
		opts,
	}
}

Functions

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func Trace

func Trace(v ...interface{})

func Tracef

func Tracef(format string, v ...interface{})

func Warning

func Warning(v ...interface{})

func Warningf

func Warningf(format string, v ...interface{})

Types

type Level

type Level int
const (
	UNKNOWN Level = iota
	TRACE
	DEBUG
	INFO
	WARNING
	ERROR
	FATAL
)

日志等级

func (Level) Color

func (level Level) Color() string

日志等级转换为颜色.

func (Level) String

func (level Level) String() string

日志等级转化为字符串.

func (Level) WordColor

func (level Level) WordColor() string

日志等级转化为字符串颜色.

type Log

type Log interface {
	Trace(v ...interface{})
	Debug(v ...interface{})
	Info(v ...interface{})
	Warning(v ...interface{})
	Error(v ...interface{})
	Fatal(v ...interface{})
	Tracef(format string, v ...interface{})
	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warningf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Fatalf(format string, v ...interface{})
}

Log 日志接口. 可以自行实现,实现后注入DefaultLogger即可使用自定义.

type Options

type Options struct {
	Path  string `yaml:"path"`
	Level Level  `yaml:"level"`
}

Jump to

Keyboard shortcuts

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