logger

package
v0.0.0-...-cda7898 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package logger is used to create a logger middleware for gin using SetLogger and a given configuration. Configuration is done using environment variables: ELASTICSEARCH_URL: The url of the elasticsearch server used by the server's logger.

default: "http://localhost:9200", can be a list of urls.

ELASTICSEARCH_USER: The user to authenticate with to elasticsearch using basic auth.

default: ""

ELASTICSEARCH_PASSWORD: The passowrd of the authenticated user in elasticsearch using basic auth. Must be set with ELASTICSEARCH_USER.

default: ""

LOG_INDEX: The index name of the server's logs in elasticsearch.

default: "log"

LOG_LEVEL: The log level of the server's logger.

default: 2 - ErrorLevel, see: logrus.AllLevels

TLS_SKIP_VERIFY: Ignore checking elasticsearch's certificate.

default: "true"

HOST_NAME: The hostname to use with the elasticsearch hook of the logger.

default: Executable name

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogError

func LogError(logger *logrus.Logger, err error)

LogError logs err with logger.Errorf if err is non-nil.

func SetLogger

func SetLogger(config *Config) gin.HandlerFunc

SetLogger initializes the logging middleware.

func StartSpan

func StartSpan(ctx context.Context, name string) (*apm.Span, context.Context)

StartSpan starts an externalGRPCSpanType span under the transaction in ctx, returns the created span and the context with the traceparent header matadata.

Types

type Config

type Config struct {
	Logger             *logrus.Logger
	SkipBodyPath       []string
	SkipBodyPathRegexp *regexp.Regexp
	SkipPath           []string
	SkipPathRegexp     *regexp.Regexp
}

Config is the configuration struct for the logger, Logger - a logrus Logger to use in the logger. SkipPath - path to skip logging. SkipPathRegexp - a regex to skip paths.

Jump to

Keyboard shortcuts

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