Back to

Package log

Latest Go to latest

The latest major version is .

Published: 1 hour ago | License: MIT | Module:



const RequestIDHeader = "Request-Id"

RequestIDHeader name of the header that can contain a request ID

func ContextWithSink

func ContextWithSink(ctx context.Context, sink *Sink) context.Context

ContextWithSink wraps the given context in a new context with the given Sink stored as value.

func Ctx

func Ctx(ctx context.Context) *zerolog.Logger

Ctx returns the logger for the passed context

func Debug

func Debug(v ...interface{})

Debug implements logrus Debug interface

func Debugf

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

Debugf implements logrus Debugf interface

func Error

func Error(v ...interface{})

Error implements logrus Error interface

func Errorf

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

Errorf implements logrus Errorf interface

func Fatal

func Fatal(v ...interface{})

Fatal implements log Fatal interface

func Fatalf

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

Fatalf implements log Fatalf interface

func Fatalln

func Fatalln(v ...interface{})

Fatalln implements log Fatalln interface

func Handler

func Handler(silentPrefixes ...string) func(http.Handler) http.Handler

Handler returns a middleware that handles all of the logging aspects of any incoming http request. Optionally several path prefixes like "/health" can be provided to decrease log spamming. All url paths with these prefixes will not be logged to the standard output but still be available in the request specific Sink.

func Info

func Info(v ...interface{})

Info implements logrus Info interface

func Infof

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

Infof implements logrus Infof interface

func Logger

func Logger() *zerolog.Logger

Logger returns the current logger instance

func Output

func Output(w io.Writer) *zerolog.Logger

Output duplicates the current logger and sets w as its output.

func Print

func Print(v ...interface{})

Print implements log Print interface

func Printf

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

Printf implements log Printf interface

func Println

func Println(v ...interface{})

Println implements log Println interface

func ProxyAwareRemote

func ProxyAwareRemote(r *http.Request) string

ProxyAwareRemote return the most likely remote address

func Req

func Req(r *http.Request) *zerolog.Logger

Req returns the logger for the passed request

func RequestID

func RequestID(r *http.Request) string

RequestID returns a unique request id or an empty string if there is none

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext returns a unique request id or an empty string if there is none

func RequestIDHandler

func RequestIDHandler(fieldKey, headerName string) func(next http.Handler) http.Handler

func SinkContextTransfer

func SinkContextTransfer(sourceCtx, targetCtx context.Context) context.Context

SinkContextTransfer gets the sink from the sourceCtx and returns a new context based on targetCtx with the extracted sink. If no sink is present this is a noop

func Stack

func Stack(ctx context.Context)

Stack prints the stack of the calling goroutine

func Warn

func Warn(v ...interface{})

Warn implements logrus Warn interface

func Warnf

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

Warnf implements logrus Warnf interface

func WithContext

func WithContext(ctx context.Context) context.Context

WithContext returns context with enabled logger. This overwrites a logger that is set on the context already use this if you are not inside a request context.

type Sink

type Sink struct {
	Silent bool
	// contains filtered or unexported fields

Sink respresents a log sink which is used to store logs, created with log.Ctx(ctx), inside the context and use them at a later point in time

func SinkFromContext

func SinkFromContext(ctx context.Context) (*Sink, bool)

SinkFromContext returns the Sink of the given context if it exists

func (*Sink) Pretty

func (s *Sink) Pretty() string

Pretty returns the logs as string while using the zerolog.ConsoleWriter to format them in a human readable way

func (*Sink) ToJSON

func (s *Sink) ToJSON() []byte

ToJSON returns a copy of the currently available logs in the Sink as json formatted []byte.

func (*Sink) Write

func (s *Sink) Write(b []byte) (int, error)

Write implements the io.Writer interface. This makes it possible to use the Sink as output in the zerolog.Output() func. Write stores all incoming logs in its internal store and calls Write() on the default output writer.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier