formatter

package module
v0.0.0-...-367fa27 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Logrus GELF Log Formatter

Logrus Only a formatter, outputs the log message in the GELF JSON format as decribed by Graylog 2.

If you are looking for a GELF hook capable of sending directly to graylog, please use this: https://github.com/gemnasium/logrus-graylog-hook

The reason for using just a formatter is that you can write files or directly to stdout in the expected format and then separately ship the lines to graylog, without stealing CPU time from your go app.

Installation

To install formatter, use go get:

$ go get github.com/seatgeek/logrus-gelf-formatter

Usage

Here is how it should be used:

package main

import (
	"github.com/sirupsen/logrus"
	gelf "github.com/seatgeek/logrus-gelf-formatter"
)

var log = logrus.New()

func init() {
	log.Formatter = new(gelf.GelfFormatter)
	log.Level = logrus.DebugLevel
}

func main() {
	log.WithFields(logrus.Fields{
		"prefix": "main",
		"animal": "walrus",
		"number": 8,
	}).Debug("Started observing beach")

	log.WithFields(logrus.Fields{
		"prefix":      "sensor",
		"temperature": -4,
	}).Info("Temperature changes")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultLevel = syslog.LOG_INFO
)

Functions

This section is empty.

Types

type GelfFormatter

type GelfFormatter struct {
}

Defines a log format type that wil output line separated JSON objects in the GELF format.

func (*GelfFormatter) Format

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

Format formats the log entry to GELF JSON

type GelfTimestampFormatter

type GelfTimestampFormatter struct{}

Defines a log format type that wil output line separated JSON objects in the GELF format.

func (*GelfTimestampFormatter) Format

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

Format formats the log entry to GELF JSON

Jump to

Keyboard shortcuts

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