dlog

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorSprintf

func ColorSprintf(c Color, format string, a ...interface{}) string

func Debug

func Debug(a ...interface{})

func DebugWithContext

func DebugWithContext(ctx context.Context, a ...interface{})

func DebugWithTraceID

func DebugWithTraceID(traceID string, a ...interface{})

func Debugf

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

func DebugfWithContext

func DebugfWithContext(ctx context.Context, format string, a ...interface{})

func DebugfWithTraceID

func DebugfWithTraceID(traceID string, format string, a ...interface{})

func Error

func Error(a ...interface{})

func ErrorWithContext

func ErrorWithContext(ctx context.Context, a ...interface{})

func ErrorWithTraceID

func ErrorWithTraceID(traceID string, a ...interface{})

func Errorf

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

func ErrorfWithContext

func ErrorfWithContext(ctx context.Context, format string, a ...interface{})

func ErrorfWithTraceID

func ErrorfWithTraceID(traceID string, format string, a ...interface{})

func Fatal

func Fatal(a ...interface{})

func FatalWithContext

func FatalWithContext(ctx context.Context, a ...interface{})

func FatalWithTraceID

func FatalWithTraceID(traceID string, a ...interface{})

func Fatalf

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

func FatalfWithContext

func FatalfWithContext(ctx context.Context, format string, a ...interface{})

func FatalfWithTraceID

func FatalfWithTraceID(traceID string, format string, a ...interface{})

func Info

func Info(a ...interface{})

func InfoWithContext

func InfoWithContext(ctx context.Context, a ...interface{})

func InfoWithTraceID

func InfoWithTraceID(traceID string, a ...interface{})

func Infof

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

func InfofWithContext

func InfofWithContext(ctx context.Context, format string, a ...interface{})

func InfofWithTraceID

func InfofWithTraceID(traceID string, format string, a ...interface{})

func NewConsoleEncodeWriter

func NewConsoleEncodeWriter() *consoleEncodeWriter

func NewFileEncodeWriter

func NewFileEncodeWriter(cfg Config) *fileEncodeWriter

func OpenLog

func OpenLog(app string, opts ...Option)

func OpenLogWithConfig added in v0.9.0

func OpenLogWithConfig(app string, cfg Config)

func Panic

func Panic(a ...interface{})

func PanicWithContext

func PanicWithContext(ctx context.Context, a ...interface{})

func PanicWithTraceID

func PanicWithTraceID(traceID string, a ...interface{})

func Panicf

func Panicf(format string, a ...interface{})

func PanicfWithContext

func PanicfWithContext(ctx context.Context, format string, a ...interface{})

func PanicfWithTraceID

func PanicfWithTraceID(traceID string, format string, a ...interface{})

func Warn

func Warn(a ...interface{})

func WarnWithContext

func WarnWithContext(ctx context.Context, a ...interface{})

func WarnWithTraceID

func WarnWithTraceID(traceID string, a ...interface{})

func Warnf

func Warnf(format string, a ...interface{})

func WarnfWithContext

func WarnfWithContext(ctx context.Context, format string, a ...interface{})

func WarnfWithTraceID

func WarnfWithTraceID(traceID string, format string, a ...interface{})

Types

type Color added in v0.9.2

type Color int
const (
	Default     Color = 00
	Black       Color = 30
	Red         Color = 31
	Green       Color = 32
	Yellow      Color = 33
	Blue        Color = 34
	PurplishRed Color = 35
	Cyan        Color = 36
	White       Color = 37
)

type Config

type Config struct {
	Level      Level      `yaml:"level" env:"LOG_LEVEL"`         //the min level for output
	WithCaller bool       `yaml:"with_caller" env:"WITH_CALLER"` //output the caller file path
	File       fileConfig `yaml:"file"`
	WithStack  bool       `yaml:"with_stack"` //output the stack while error level
	// contains filtered or unexported fields
}

type EncodeWriter

type EncodeWriter interface {
	Encoder(entry *Entry) ([]byte, error)
	Write([]byte) (int, error)
}

type Entry

type Entry struct {
	LoggerName string
	Level      Level
	Time       time.Time
	TraceID    string
	Message    string
	Caller     string
	Stack      string
}

type ILogger

type ILogger interface {
	LogWithContext(ctx context.Context, level Level, a ...interface{})
	LogfWithContext(ctx context.Context, level Level, format string, a ...interface{})
}

func New

func New(cfg Config) ILogger

type Level

type Level int8
const (
	// DebugLevel logs are typically voluminous, and are usually disabled in production.
	DebugLevel Level = iota
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

func (Level) Color

func (l Level) Color() Color

Color 日志终端输出颜色

func (Level) String

func (l Level) String() string

String 日志等级标识

func (*Level) UnmarshalYAML added in v0.9.0

func (l *Level) UnmarshalYAML(value *yaml.Node) error

type Logger

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

func (*Logger) LogWithContext

func (log *Logger) LogWithContext(ctx context.Context, level Level, a ...interface{})

func (*Logger) LogfWithContext

func (log *Logger) LogfWithContext(ctx context.Context, level Level, format string, a ...interface{})

type Option

type Option func(cfg *Config) *Config

func WithCaller

func WithCaller() Option

WithCaller 打印日志输出位置

func WithFile

func WithFile(basePath string) Option

WithFile 输出到文件

func WithFileMaxAge

func WithFileMaxAge(maxAge int) Option

WithFileMaxAge 设置日志最大生命周期(天)

func WithLevel

func WithLevel(l Level) Option

WithLevel 设置日志最低输出等级

func WithMinDiskSpace

func WithMinDiskSpace(minDiskSpaceSize uint64) Option

WithMinDiskSpace 设置最低磁盘空间大小(MB)

func WithStack

func WithStack() Option

WithStack 输出堆栈信息

Jump to

Keyboard shortcuts

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