log

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 12 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 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(o string)

SetOutput sets the logger output.

func Writer

func Writer(output string) io.Writer

Writer get an io.Writer according to the 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.

Jump to

Keyboard shortcuts

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