logger

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindCaller

func FindCaller(callerSkip int) (lastCaller, allCallers string)

Types

type Field

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

func Any

func Any(key string, val interface{}) Field

type ILogger

type ILogger interface {
	Write(msg []byte)
	Enable(level Level) bool
	Log(msg string, level Level, fields ...Field)
	Logf(level Level, format string, v ...interface{})
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Infof(format string, args ...interface{})
	Warn(msg string, fields ...Field)
	Warnf(format string, args ...interface{})
	Error(msg string, fields ...Field)
	Errorf(format string, args ...interface{})
	Panic(msg string, fields ...Field)
	Panicf(format string, args ...interface{})
	Fatal(msg string, fields ...Field)
	Fatalf(format string, args ...interface{})
}

func New

func New() ILogger

func NewWithOptions

func NewWithOptions(opts ...Option) ILogger

type Level

type Level uint8
const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

func GetLevel

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) String

func (l Level) String() string

type Logger

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

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...Field)

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

func (*Logger) Enable

func (l *Logger) Enable(level Level) bool

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...Field)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...Field)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...Field)

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) Log

func (l *Logger) Log(msg string, level Level, fields ...Field)

func (*Logger) Logf

func (l *Logger) Logf(level Level, format string, v ...interface{})

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...Field)

func (*Logger) Panicf

func (l *Logger) Panicf(format string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...Field)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

func (*Logger) Write

func (l *Logger) Write(msg []byte)

type Option

type Option func(l *Logger)

func WithCallerSkip

func WithCallerSkip(callerSkip int) Option

func WithCompress

func WithCompress(compress bool) Option

func WithFields

func WithFields(fields ...Field) Option

func WithInterval

func WithInterval(interval time.Duration) Option

func WithLevel

func WithLevel(level string) Option

func WithMaxAge

func WithMaxAge(maxAge int) Option

func WithMaxBackups

func WithMaxBackups(maxBackups int) Option

func WithMaxSize

func WithMaxSize(maxSize int) Option

func WithName

func WithName(name string) Option

func WithOutType

func WithOutType(outType string) Option

func WithPath

func WithPath(path string) Option

type RotateWriter

type RotateWriter struct {
	// Filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-rotate.log in
	// os.TempDir() if empty.
	Filename string

	// MaxSize is the maximum size in megabytes of the log file before it gets
	// rotated. It defaults to 100 megabytes.
	MaxSize int

	// MaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename.  Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is not to remove old log files
	// based on age.
	MaxAge int

	// MaxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int

	// Compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool

	// Interval determines the duration to rotate log files.
	// The default is not to rotate log files based on time.
	Interval time.Duration
	// contains filtered or unexported fields
}

func (*RotateWriter) Write

func (r *RotateWriter) Write(p []byte) (n int, err error)

type Type

type Type uint8
const (
	Stdout Type = iota
	File
	FileAndStdout
)

func GetType

func GetType(typeStr string) (Type, error)

Jump to

Keyboard shortcuts

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