Documentation ¶
Index ¶
- Constants
- func ActiveTraceIdValue(c context.Context) string
- func AddField(c context.Context, key string, value interface{}) context.Context
- func AddFieldAndGet(c context.Context, key string, value interface{}) (context.Context, *logrus.Entry)
- func AddFields(c context.Context, fields map[string]interface{}) context.Context
- func AddFieldsAndGet(c context.Context, fields map[string]interface{}) (context.Context, *logrus.Entry)
- func IsTty() bool
- func Logger(c context.Context) *logrus.Entry
- func LoggerOrNil(c context.Context) *logrus.Entry
- func NewLogger(cfg NewLoggerInput) (*logrus.Entry, error)
- func WithLogger(c context.Context, logger *logrus.Entry) context.Context
- func WithNullLogger(c context.Context) (context.Context, *test.Hook)
- func WithTraceId(c context.Context, key TraceIdKey) context.Context
- func WithTracingLogger(c context.Context) context.Context
- type NewLoggerInput
- type TraceIdKey
Constants ¶
const LoggerKey = "logger"
Variables ¶
This section is empty.
Functions ¶
func ActiveTraceIdValue ¶
ActiveTraceIdValue returns the value part of ActiveTraceId (does not return the TradeIdKey type part).
func AddFieldAndGet ¶
func AddFieldsAndGet ¶
func WithLogger ¶
WithLogger returns a new context that adds a logger which can be retrieved with Logger(Context).
func WithNullLogger ¶
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 ¶
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 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.