logctx

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

View Source
const LoggerKey = "logger"

Variables

This section is empty.

Functions

func ActiveTraceIdValue

func ActiveTraceIdValue(c context.Context) string

ActiveTraceIdValue returns the value part of ActiveTraceId (does not return the TradeIdKey type part).

func AddField

func AddField(c context.Context, key string, value interface{}) context.Context

func AddFieldAndGet

func AddFieldAndGet(c context.Context, key string, value interface{}) (context.Context, *logrus.Entry)

func AddFields

func AddFields(c context.Context, fields map[string]interface{}) context.Context

func AddFieldsAndGet

func AddFieldsAndGet(c context.Context, fields map[string]interface{}) (context.Context, *logrus.Entry)

func IsTty

func IsTty() bool

func Logger

func Logger(c context.Context) *logrus.Entry

func LoggerOrNil

func LoggerOrNil(c context.Context) *logrus.Entry

func NewLogger

func NewLogger(cfg NewLoggerInput) (*logrus.Entry, error)

func WithLogger

func WithLogger(c context.Context, logger *logrus.Entry) context.Context

WithLogger returns a new context that adds a logger which can be retrieved with Logger(Context).

func WithNullLogger

func WithNullLogger(c context.Context) (context.Context, *test.Hook)

WithNullLogger adds the logger from test.NewNullLogger into the given context (default c to context.Background). Use the hook to get the log messages. See https://github.com/sirupsen/logrus#testing for testing with logrus.

func WithTraceId

func WithTraceId(c context.Context, key TraceIdKey) context.Context

func WithTracingLogger

func WithTracingLogger(c context.Context) context.Context

WithTracingLogger stiches together WithTraceId and WithLogger. It extracts the ActiveTraceId and sets it on the logger. In this way you can do WithTracingLogger(WithTraceId(WithLogger(ctx, logger))) to get a logger in the context with a trace id, and then Logger to get the logger back.

Types

type NewLoggerInput

type NewLoggerInput struct {
	Level     string
	Format    string
	File      string
	BuildSha  string
	BuildTime string
	Fields    logrus.Fields
}

type TraceIdKey

type TraceIdKey string
const JobTraceIdKey TraceIdKey = "job_trace_id"

JobTraceIdKey is the trace ID key for when we run jobs in the background, like cron jobs.

const MissingTraceIdKey TraceIdKey = "missing_trace_id"

MissingTraceIdKey is the key that will be present to indicate tracing is misconfigured.

const ProcessTraceIdKey TraceIdKey = "process_trace_id"

ProcessTraceIdKey is the trace ID key for the overall process.

const RequestTraceIdKey TraceIdKey = "trace_id"

RequestTraceIdKey is the trace ID key for requests.

func ActiveTraceId

func ActiveTraceId(c context.Context) (TraceIdKey, string)

ActiveTraceId returns the first valid trace value and type from the given context, or MissingTraceIdKey if there is none.

Jump to

Keyboard shortcuts

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