log

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0, BSD-3-Clause, MIT Imports: 12 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// FieldComponentName is the key of the component field in the log message.
	FieldComponentName = "component"
	// FieldCorrelationID is the key of the correlation id field in the log message.
	FieldCorrelationID = "correlation_id"
)

Variables

View Source
var (

	// C is an alias for ForContext
	C = ForContext
	// D is an alias for DefaultLogger
	D = DefaultLogger
)
View Source
var CorrelationIDHeaders = []string{"X-CorrelationID", "X-Correlation-ID", "X-ForRequest-ID", "X-Request-ID", "X-Vcap-Request-Id", "X-Broker-API-Request-Identity"}

CorrelationIDHeaders are the headers whose values will be taken as a correlation id for incoming requests The first one will be set on outgoing requests

Functions

func AddHook

func AddHook(hook logrus.Hook)

AddHook adds a hook to all loggers

func Configure

func Configure(ctx context.Context, settings *Settings) (context.Context, error)

Configure creates a new context with a logger using the provided settings.

func ContextWithLogger

func ContextWithLogger(ctx context.Context, entry *logrus.Entry) context.Context

ContextWithLogger returns a new context with the provided logger.

func CorrelationIDForRequest

func CorrelationIDForRequest(request *http.Request) string

CorrelationIDForRequest returns checks the http headers for any of the supported correlation id headers. The first that matches is taken as the correlation id. If none exists a new one is generated.

func CorrelationIDFromContext added in v0.5.0

func CorrelationIDFromContext(ctx context.Context) string

CorrelationIDFromContext returns the correlation id associated with the context logger or empty string if none exists

func DefaultLogger added in v0.18.7

func DefaultLogger() *logrus.Entry

DefaultLogger returns the default logger

func ForContext

func ForContext(ctx context.Context) *logrus.Entry

ForContext retrieves the current logger from the context.

func RegisterFormatter

func RegisterFormatter(name string, formatter logrus.Formatter) error

RegisterFormatter registers a new logrus Formatter with the given name. Returns an error if there is a formatter with the same name.

Types

type KibanaFormatter added in v0.5.0

type KibanaFormatter struct {
}

KibanaFormatter is a logrus formatter that formats an entry for Kibana

func (*KibanaFormatter) Format added in v0.5.0

func (f *KibanaFormatter) Format(e *logrus.Entry) ([]byte, error)

Format formats a logrus entry for Kibana logging

type Settings

type Settings struct {
	Level  string `description:"minimum level for log messages" json:"level,omitempty"`
	Format string `description:"format of log messages. Allowed values - text, json" json:"format,omitempty"`
	Output string `description:"output for the logs. Allowed values - /dev/stdout, /dev/stderr, ginkgowriter" json:"output,omitempty"`
}

Settings type to be loaded from the environment

func Configuration added in v0.5.0

func Configuration() Settings

Configuration returns the logger settings

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns default values for Log settings

func (*Settings) Validate

func (s *Settings) Validate() error

Validate validates the logging settings

Jump to

Keyboard shortcuts

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