cslog

package
v0.0.0-...-788e3c4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: AGPL-3.0 Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpanID

func GetSpanID(ctx context.Context) string

GetSpanID returns the current spanID in the context

func GetSpanIDFromHeaders

func GetSpanIDFromHeaders(r *http.Request) string

GetSpanIDFromHeaders returns the span ID from the request headers

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID returns the current traceID in the context

func GetTraceIDFromHeaders

func GetTraceIDFromHeaders(r *http.Request) string

GetTraceIDFromHeaders returns the trace ID from the request headers

func SetSpanIDAndTraceIDInHeaders

func SetSpanIDAndTraceIDInHeaders(ctx context.Context, r *http.Request)

SetSpanIDAndTraceIDInHeaders sets headers in the request to pass along the span and trace IDs in the context

func StoreSpanID

func StoreSpanID(ctx context.Context, spanID string) context.Context

StoreSpanID returns a context with a stored spanID

func StoreSpanIDTraceID

func StoreSpanIDTraceID(ctx context.Context, spanID, traceID string) context.Context

StoreSpanIDTraceID store both SpanID and TraceID

func StoreTraceID

func StoreTraceID(ctx context.Context, traceID string) context.Context

StoreTraceID returns a context with a stored traceID

Types

type CSLogger

type CSLogger struct {
	// contains filtered or unexported fields
}

CSLogger controls the format of logs written to the underylying LogWriter

func NewCSLogger

func NewCSLogger(lw LogWriter, uuidGenerator fmt.Stringer) *CSLogger

NewCSLogger returns a new CSLogger holding the provided LogWriter

NOTE: uuidGenerator uses a valid a default for the constructor if one is not provided

func (*CSLogger) Close

func (l *CSLogger) Close(ctx context.Context, c io.Closer)

Close closes the io.Closer and logs the returned error if it is non-nil

func (*CSLogger) Error

func (l *CSLogger) Error(ctx context.Context, msg string, args ...interface{})

Error writes ERROR-lvl logs, but takes input as a string

func (*CSLogger) Info

func (l *CSLogger) Info(ctx context.Context, msg string, args ...interface{})

Info writes INFO-lvl logs

func (*CSLogger) Invalid

func (l *CSLogger) Invalid(ctx context.Context, subj interface{}, reason string)

Invalid writes logs for failed validation events

func (*CSLogger) Query

func (l *CSLogger) Query(ctx context.Context, qry string, args ...interface{})

Query writes QUERY-lvl logs

func (*CSLogger) Warn

func (l *CSLogger) Warn(ctx context.Context, msg string, args ...interface{})

Warn writes WARN-lvl logs

type CtxKey

type CtxKey string

CtxKey is the type for all ctx keys in the cslog package

const (
	// SpanIDCtxKey keys the SpanID in the context
	SpanIDCtxKey CtxKey = "span_id"

	// TraceIDCtxKey keys the TraceID in the context
	TraceIDCtxKey CtxKey = "trace_id"
)

type LogJSON

type LogJSON struct {
	Level   string                 `json:"level"`
	Message string                 `json:"message"`
	SpanID  string                 `json:"span_id"`
	TraceID string                 `json:"trace_id"`
	Data    map[string]interface{} `json:"data,omitempty"`
}

LogJSON is the structure of the JSON logs

type LogWriter

type LogWriter interface {
	Println(v ...interface{})
}

LogWriter writes to the concrete type that

type Logger

type Logger interface {
	// generic logging
	// Debug(ctx context.Context, msg string, args ...interface{})
	Error(ctx context.Context, msg string, args ...interface{})
	Info(ctx context.Context, msg string, args ...interface{})

	// specific event logging
	Close(ctx context.Context, c io.Closer)
	Invalid(ctx context.Context, subj interface{}, reason string)
	Query(ctx context.Context, qry string, args ...interface{})
}

Logger represents anything that can format logs correctly

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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