ecslogrus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: Apache-2.0 Imports: 4 Imported by: 42

README

Elastic Common Schema (ECS) support for Logrus

Use this library for automatically adding a minimal set of ECS fields to your logs, when using logrus.

Documentation

Ready to get started? Documentation is at elastic.co.

Test

go test ./...

Contribute

Create a Pull Request from your own fork.

Run mage to update and format you changes before submitting.

Add new dependencies to the NOTICE.txt.

License

This software is licensed under the Apache 2 license.

Documentation

Overview

Package ecslogrus provides a formatter to be used with the github.com/sirupsen/logrus logger library that helps creating Elastic Common Schema (ECS) conformant log entries.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	// DisableHTMLEscape allows disabling html escaping in output
	DisableHTMLEscape bool

	// DataKey allows users to put all the log entry parameters into a
	// nested dictionary at a given key.
	//
	// DataKey is ignored for well-defined fields, such as "error",
	// which will instead be stored under the appropriate ECS fields.
	DataKey string

	// CallerPrettyfier can be set by the user to modify the content
	// of the function and file keys in the json data when ReportCaller is
	// activated. If any of the returned value is the empty string the
	// corresponding key will be removed from json fields.
	CallerPrettyfier func(*runtime.Frame) (function string, file string)

	// PrettyPrint will indent all json logs
	PrettyPrint bool
}

Formatter is a logrus.Formatter, formatting log entries as ECS-compliant JSON.

Example
package main

import (
	"os"
	"time"

	"github.com/sirupsen/logrus"
	"go.elastic.co/ecslogrus"
)

func main() {
	log := logrus.New()
	log.SetOutput(os.Stdout)
	log.SetFormatter(&ecslogrus.Formatter{})

	epoch := time.Unix(0, 0).UTC()
	log.WithTime(epoch).WithField("custom", "foo").Info("hello")

}
Output:

{"@timestamp":"1970-01-01T00:00:00.000Z","custom":"foo","ecs.version":"1.6.0","log.level":"info","message":"hello"}

func (*Formatter) Format

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

Format formats e as ECS-compliant JSON.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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