bricks: github.com/pace/bricks/maintenance/log Index | Files

package log

import "github.com/pace/bricks/maintenance/log"

Index

Package Files

handler.go log.go log_api.go logrus_api.go sink.go

Constants

const RequestIDHeader = "Request-Id"

RequestIDHeader name of the header that can contain a request ID

func ContextWithSink Uses

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 Uses

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

Ctx returns the logger for the passed context

func Debug Uses

func Debug(v ...interface{})

Debug implements logrus Debug interface

func Debugf Uses

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

Debugf implements logrus Debugf interface

func Error Uses

func Error(v ...interface{})

Error implements logrus Error interface

func Errorf Uses

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

Errorf implements logrus Errorf interface

func Fatal Uses

func Fatal(v ...interface{})

Fatal implements log Fatal interface

func Fatalf Uses

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

Fatalf implements log Fatalf interface

func Fatalln Uses

func Fatalln(v ...interface{})

Fatalln implements log Fatalln interface

func Handler Uses

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 Uses

func Info(v ...interface{})

Info implements logrus Info interface

func Infof Uses

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

Infof implements logrus Infof interface

func Logger Uses

func Logger() *zerolog.Logger

Logger returns the current logger instance

func Output Uses

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

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

func Print Uses

func Print(v ...interface{})

Print implements log Print interface

func Printf Uses

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

Printf implements log Printf interface

func Println Uses

func Println(v ...interface{})

Println implements log Println interface

func ProxyAwareRemote Uses

func ProxyAwareRemote(r *http.Request) string

ProxyAwareRemote return the most likely remote address

func Req Uses

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

Req returns the logger for the passed request

func RequestID Uses

func RequestID(r *http.Request) string

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

func RequestIDFromContext Uses

func RequestIDFromContext(ctx context.Context) string

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

func RequestIDHandler Uses

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

func SinkContextTransfer Uses

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 Uses

func Stack(ctx context.Context)

Stack prints the stack of the calling goroutine

func Warn Uses

func Warn(v ...interface{})

Warn implements logrus Warn interface

func Warnf Uses

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

Warnf implements logrus Warnf interface

func WithContext Uses

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 Uses

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 Uses

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

SinkFromContext returns the Sink of the given context if it exists

func (*Sink) Pretty Uses

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 Uses

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

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

func (*Sink) Write Uses

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 log imports 21 packages (graph) and is imported by 14 packages. Updated 2020-08-06. Refresh now. Tools for package owners.