log

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug   = log.Debug
	Debugf  = log.Debugf
	Error   = log.Error
	Errorf  = log.Errorf
	Fatal   = log.Fatal
	Fatalf  = log.Fatalf
	Info    = log.Info
	Infof   = log.Infof
	Print   = log.Print
	Printf  = log.Printf
	Println = log.Println
	Trace   = log.Trace
	Tracef  = log.Tracef
	Warn    = log.Warn
	Warnf   = log.Warnf

	WithContext = log.WithContext
	WithError   = log.WithError
	WithField   = log.WithField
	WithFields  = log.WithFields

	RegisterExitHandler = logrus.RegisterExitHandler
)

define aliases to logrus.

View Source
var (
	// JSONLogFormatter formats logs into parsable json.
	JSONLogFormatter = &logrus.JSONFormatter{TimestampFormat: "2006-01-02T15:04:05.000-07:00", CallerPrettyfier: callerPretty, DisableHTMLEscape: true}

	// TextLogFormatter formats logs into text.
	TextLogFormatter = &logrus.TextFormatter{TimestampFormat: "2006-01-02T15:04:05.000-07:00", FullTimestamp: true, CallerPrettyfier: callerPretty}
)

Functions

func ContextWithFields added in v0.2.1

func ContextWithFields(ctx context.Context, fields Fields)

ContextWithFields persist fields into context if the context contains dataContextHook.

func DataContext added in v0.2.1

func DataContext(ctx context.Context, opts ...DataContextOptions) context.Context

DataContext set data to context. The dataContextHook will read it. If an empty requestID is passed in, a random one will be generated.

func IsDebugEnabled

func IsDebugEnabled() bool

IsDebugEnabled checks if the log level is greater than the debug level.

func Log

func Log() *logrus.Logger

Log returns the default logger.

func New

func New() *logrus.Logger

New creates a new logger.

func NewRequestID added in v0.2.1

func NewRequestID() string

NewRequestID returns a random request id.

func Output added in v0.3.0

func Output(filename string, options *OutputOptions) io.Writer

Output get an io.Writer according to the filename and options.

func RequestIDFromContext added in v0.3.0

func RequestIDFromContext(ctx context.Context) (string, time.Time)

RequestIDFromContext returns the requestID in context.

func SetFormatter

func SetFormatter(f string, pretty bool)

SetFormatter sets the standard logger formatter.

func SetLevel

func SetLevel(l string)

SetLevel sets the logger level.

func SetOutput

func SetOutput(filename string, options *OutputOptions)

SetOutput sets the logger output.

Types

type DataContextOptions added in v0.2.1

type DataContextOptions struct {
	RequestID string
	Fields    Fields
}

DataContextOptions is the options to DataContext.

type Fields

type Fields = logrus.Fields

define type aliases to logrus.

type Logger

type Logger = logrus.Logger

define type aliases to logrus.

type OutputOptions added in v0.3.0

type OutputOptions struct {
	Rotate      string // options: d or day, h or hour
	MaxSizeInMB int
	MaxAgeInDay int
	MaxBackups  int
}

OutputOptions set the options to the log output files.

type Report added in v0.3.0

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

Report is used for data reporting.

func NewReport added in v0.3.0

func NewReport(action string) *Report

NewReport returns a new instance.

func (*Report) Done added in v0.3.0

func (r *Report) Done()

Done writes the report data to file.

func (*Report) Set added in v0.3.0

func (r *Report) Set(k string, v any) *Report

Set key and value.

func (*Report) Sets added in v0.3.0

func (r *Report) Sets(kvs map[string]any) *Report

Sets key value pairs from map.

Jump to

Keyboard shortcuts

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