Skip to content

Logrus logging formatter which produces gelf to stdout

Notifications You must be signed in to change notification settings

ballad89/gelfFormatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GelfFormatter

This is a logrus formatter which formats log messages into valid gelf for graylog

This library is hugely based on the graylog gelf library but differs in that it is complaint with 12 factor log principles, which states ...

A twelve-factor app never concerns itself with routing or storage of its output stream.
It should not attempt to write to or manage logfiles.
Instead, each running process writes its event stream, unbuffered, to stdout.
During local development, the developer will view this stream in the foreground of their terminal to observe the app’s behavior.

In staging or production deploys, each process’ stream will be captured by the execution environment, collated together with all other streams from the app, and routed to one or more final destinations for viewing and long-term archival.
These archival destinations are not visible to or configurable by the app, and instead are completely managed by the execution environment.
Open-source log routers (such as Logplex and Fluent) are available for this purpose.

Installation

go get -u github.com/ballad89/gelfFormatter
package main

import (
    "github.com/ballad89/gelfFormatter"
    log "github.com/sirupsen/logrus"
    
)

func main() {

    f, err := gelfFormatter.NewGelfFormatter("application-name")

    if err != nil {
        panic(err)
    }
    log.SetFormatter(f)

    log.SetOutput(os.Stdout)

    log.WithFields(log.Fields{
        "animal": "walrus",
    }).Info("animal")
}
{"version":"1.1","host":"machine.name","short_message":"animal","timestamp":1502245262,"level":6,"_facility":"application-name","_animal":"walrus"}

About

Logrus logging formatter which produces gelf to stdout

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages