Skip to content

xild/go-gelf-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Logrus Gelf Formatter

Formatter - Format your LogRus log in GELF FORMAT.

Formatter

All logrus.Fields are printed like additional fields in gelf format.

If you set a envrionment variable with APPLICATION_NAME the formatter will print a additional field called _appName

If there are newlines in the message, use the first line for the short message and set the full message to the original input

The code bellow will print:

{
    "version": "1.0",
    "host": "MACHINE_NAME os.GET",
    "short_message": "A group of walrus emerges from the ocean",
    "full_message": "A group of walrus emerges from the ocean The ocean That's all I need",
    "timestamp": "2016-09-19T10:57:42-03:00",
    "level": 6,
    "file": "",
    "line": 0,
    "_animal": "walrus",
    "_size": 10
}
package main

import (
  log "github.com/Sirupsen/logrus"
  "github.com/xild/go-gelf-formatter"
)

func init() {
  // Log as GELF FORMATTER instead of the default ASCII formatter.
  log.SetFormatter(&xild.GELFFormatter{})
}

func main() {
  log.WithFields(log.Fields{
    "animal": "walrus",
    "size":   10,
  }).Info("A group of walrus emerges from the ocean \n The ocean That's all I need")
}

Contributing:

If you find any improvement or issue you want to fix, feel free to send me a pull request with testing.

Credits

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages