logx

package
v1.0.50 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InfoLevel logs everything
	InfoLevel = iota
	// ErrorLevel includes errors, slows, stacks
	ErrorLevel
	// SevereLevel only log severe messages
	SevereLevel
)

Variables

View Source
var (
	ErrLogPathNotSet        = errors.New("log path must be set")
	ErrLogNotInitialized    = errors.New("log not initialized")
	ErrLogServiceNameNotSet = errors.New("log service name must be set")
)
View Source
var ErrLogFileClosed = errors.New("error: log file closed")

Functions

func Alert

func Alert(v string)

func Close

func Close() error

func CollectSysLog

func CollectSysLog()

CollectSysLog redirects system log into logx info

func Disable

func Disable()

func Error

func Error(v ...interface{})

func ErrorCaller

func ErrorCaller(callDepth int, v ...interface{})

func ErrorCallerf

func ErrorCallerf(callDepth int, format string, v ...interface{})

func ErrorStack

func ErrorStack(v ...interface{})

func ErrorStackf

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

func Errorf

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

func Info

func Info(v ...interface{})

func Infof

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

func Must

func Must(err error)

func MustSetup

func MustSetup(c LogConf)

func NewLessWriter

func NewLessWriter(writer io.Writer, milliseconds int) *lessWriter

func SetLevel

func SetLevel(level uint32)

func SetUp

func SetUp(c LogConf) error

SetUp sets up the logx. If already set up, just return nil. we allow SetUp to be called multiple times, because for example we need to allow different service frameworks to initialize logx respectively. the same logic for SetUp

func Severe

func Severe(v ...interface{})

func Severef

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

func Slow

func Slow(v ...interface{})

func Slowf

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

func Stat

func Stat(v ...interface{})

func Statf

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

Types

type DailyRotateRule

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

func (*DailyRotateRule) BackupFileName

func (r *DailyRotateRule) BackupFileName() string

func (*DailyRotateRule) MarkRotated

func (r *DailyRotateRule) MarkRotated()

func (*DailyRotateRule) OutdatedFiles

func (r *DailyRotateRule) OutdatedFiles() []string

func (*DailyRotateRule) ShallRotate

func (r *DailyRotateRule) ShallRotate() bool

type LessLogger

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

func NewLessLogger

func NewLessLogger(milliseconds int) *LessLogger

func (*LessLogger) Error

func (logger *LessLogger) Error(v ...interface{})

func (*LessLogger) Errorf

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

type LogConf

type LogConf struct {
	ServiceName         string `json:",optional"`
	Mode                string `json:",default=console,options=console|file|volume"`
	Path                string `json:",default=logs"`
	Level               string `json:",default=info,options=info|error|severe"`
	Compress            bool   `json:",optional"`
	KeepDays            int    `json:",optional"`
	StackCooldownMillis int    `json:",default=100"`
}

type LogOption

type LogOption func(options *logOptions)

func WithCooldownMillis

func WithCooldownMillis(millis int) LogOption

func WithGzip

func WithGzip() LogOption

func WithKeepDays

func WithKeepDays(days int) LogOption

type Logger

type Logger interface {
	Error(...interface{})
	Errorf(string, ...interface{})
	Info(...interface{})
	Infof(string, ...interface{})
	Slow(...interface{})
	Slowf(string, ...interface{})
	WithDuration(time.Duration) Logger
}

func WithContext

func WithContext(ctx context.Context) Logger

func WithDuration

func WithDuration(d time.Duration) Logger

type RotateLogger

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

func NewLogger

func NewLogger(filename string, rule RotateRule, compress bool) (*RotateLogger, error)

func (*RotateLogger) Close

func (l *RotateLogger) Close() error

func (*RotateLogger) Write

func (l *RotateLogger) Write(data []byte) (int, error)

type RotateRule

type RotateRule interface {
	BackupFileName() string
	MarkRotated()
	OutdatedFiles() []string
	ShallRotate() bool
}

func DefaultRotateRule

func DefaultRotateRule(filename, delimiter string, days int, gzip bool) RotateRule

Jump to

Keyboard shortcuts

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