logger

package module
v0.0.0-...-3d0c4d4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2018 License: MIT Imports: 8 Imported by: 0

README

go-ecs-logger

Logrus formatter that generates logs for ecs-logs forwarder.

This package contains a formatter and a http.Handler that will log requests.

Usage

Set the formatter for the default logger by doing

import (
	"bitbucket.org/ldfrtm/go-ecs-logger"
	"github.com/sirupsen/logrus"
)

func init() {
	logrus.SetFormatter(logger.NewFormatter())
}

Output

Follows the format of ecs-logs and adds every structured field inside "data" : {}.

Documentation

Index

Constants

View Source
const (
	// FieldKeyMsg is the key for message
	FieldKeyMsg = "message"
	// FieldKeyLevel is the key for level
	FieldKeyLevel = "level"
	// FieldKeyTime is the key for time
	FieldKeyTime = "time"
	// FieldKeyData is the key for data
	FieldKeyData = "data"
	// DefaultTimestampFormat is the default formtat for presenting time
	DefaultTimestampFormat = time.RFC3339
)

Variables

This section is empty.

Functions

func Handler

func Handler(h http.Handler) http.Handler

Handler uses Logging handler with a new handler

func LoggingHandler

func LoggingHandler(l logrus.FieldLogger, h http.Handler) http.Handler

LoggingHandler return a http.Handler that wraps h and logs requests to out in ECS Format

Types

type ECSFormatter

type ECSFormatter struct {
	// TimestampFormat sets the format used for marshaling timestamps.
	TimestampFormat string

	// DisableTimestamp allows disabling automatic timestamps in output
	DisableTimestamp bool

	// FieldMap allows users to customize the names of keys for various fields.
	// As an example:
	// formatter := &JSONFormatter{
	//   	FieldMap: FieldMap{
	// 		 FieldKeyTime: "@timestamp",
	// 		 FieldKeyLevel: "@level",
	// 		 FieldKeyMsg: "@message",
	//    },
	// }
	FieldMap FieldMap
}

ECSFormatter formats logs in ecs-logger compatible format with fields inside data

func NewFormatter

func NewFormatter() *ECSFormatter

NewFormatter creates a new instance of ECS Formatter.

func (*ECSFormatter) Format

func (f *ECSFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format formats an entry according to logrus

type FieldMap

type FieldMap map[fieldKey]string

FieldMap contains all the fields that go into log entries

Jump to

Keyboard shortcuts

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