logrusctx

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

README

logrusctx reference tests

Port of github.com/juju/zaputil/zapctx for github.com/sirupsen/logrus

Example

package main

import (
	"context"

	"github.com/sirupsen/logrus"
	"github.com/0x2b3bfa0/logrusctx"
)

func main() {
	ctx := context.Background()
	logger := logrus.WithField("key", "value")

	ctx = logrusctx.WithLogger(ctx, logger)
	worker(ctx)
}

func worker(ctx context.Context) {
	logrusctx.Info(ctx, "test")
}

Documentation

Index

Constants

This section is empty.

Variables

Default holds the logger entry returned by Entry when there is no logger in the context.

Functions

func Debug

func Debug(ctx context.Context, args ...interface{})

Debug calls Logger(ctx).Debug(args...)

func Debugf

func Debugf(ctx context.Context, format string, args ...interface{})

Debugf calls Logger(ctx).Debugf(format string, args...)

func Debugln

func Debugln(ctx context.Context, args ...interface{})

Debugln calls Logger(ctx).Debugln(args...)

func Error

func Error(ctx context.Context, args ...interface{})

Error calls Logger(ctx).Error(args...)

func Errorf

func Errorf(ctx context.Context, format string, args ...interface{})

Errorf calls Logger(ctx).Errorf(format string, args...)

func Errorln

func Errorln(ctx context.Context, args ...interface{})

Errorln calls Logger(ctx).Errorln(args...)

func Fatal

func Fatal(ctx context.Context, args ...interface{})

Fatal calls Logger(ctx).Fatal(args...)

func Fatalf

func Fatalf(ctx context.Context, format string, args ...interface{})

Fatalf calls Logger(ctx).Fatalf(format string, args...)

func Fatalln

func Fatalln(ctx context.Context, args ...interface{})

Fatalln calls Logger(ctx).Fatalln(args...)

func Info

func Info(ctx context.Context, args ...interface{})

Info calls Logger(ctx).Info(args...)

func Infof

func Infof(ctx context.Context, format string, args ...interface{})

Infof calls Logger(ctx).Infof(format string, args...)

func Infoln

func Infoln(ctx context.Context, args ...interface{})

Infoln calls Logger(ctx).Infoln(args...)

func Panic

func Panic(ctx context.Context, args ...interface{})

Panic calls Logger(ctx).Panic(args...)

func Panicf

func Panicf(ctx context.Context, format string, args ...interface{})

Panicf calls Logger(ctx).Panicf(format string, args...)

func Panicln

func Panicln(ctx context.Context, args ...interface{})

Panicln calls Logger(ctx).Panicln(args...)

func Print

func Print(ctx context.Context, args ...interface{})

Print calls Logger(ctx).Print(args...)

func Printf

func Printf(ctx context.Context, format string, args ...interface{})

Printf calls Logger(ctx).Printf(format string, args...)

func Println

func Println(ctx context.Context, args ...interface{})

Println calls Logger(ctx).Println(args...)

func Warn

func Warn(ctx context.Context, args ...interface{})

Warn calls Logger(ctx).Warn(args...)

func Warnf

func Warnf(ctx context.Context, format string, args ...interface{})

Warnf calls Logger(ctx).Warnf(format string, args...)

func Warning

func Warning(ctx context.Context, args ...interface{})

Warning calls Logger(ctx).Warning(args...)

func Warningf

func Warningf(ctx context.Context, format string, args ...interface{})

Warningf calls Logger(ctx).Warningf(format string, args...)

func Warningln

func Warningln(ctx context.Context, args ...interface{})

Warningln calls Logger(ctx).Warningln(args...)

func Warnln

func Warnln(ctx context.Context, args ...interface{})

Warnln calls Logger(ctx).Warnln(args...)

func WithContext

func WithContext(ctx context.Context) context.Context

WithContext creates an entry from the standard logger and adds a context to it.

func WithError

func WithError(ctx context.Context, err error) context.Context

WithError creates an entry from the standard logger and adds an error to it, using the value defined in logrus.ErrorKey as key.

func WithField

func WithField(ctx context.Context, key string, value interface{}) context.Context

WithField returns a new context derived from ctx that has a logger that always logs the given field.

func WithFields

func WithFields(ctx context.Context, fields logrus.Fields) context.Context

WithFields returns a new context derived from ctx that has a logger that always logs the given fields.

func WithLogger

func WithLogger(ctx context.Context, logger ExtendedFieldLogger) context.Context

WithLogger returns a new context derived from ctx that is associated with the given logger.

func WithTime

func WithTime(ctx context.Context, t time.Time) context.Context

WithTime creates an entry from the standard logger and overrides the time of logs generated with it.

Types

type ExtendedFieldLogger

type ExtendedFieldLogger interface {
	WithContext(ctx context.Context) *logrus.Entry
	WithTime(t time.Time) *logrus.Entry
	logrus.FieldLogger
}

ExtendedFieldLogger generalizes the Entry and Logger types.

func Logger

Logger returns the logger associated with the given context. If there is no logger, it will return Default.

Jump to

Keyboard shortcuts

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