Giter Site home page Giter Site logo

go-logrus-formatters's Introduction

go-logrus-formatters Build Status

This repository contains a set of logrus formatters.

Installation

Since this project supports semver, preferred way of installation is through dep or gomodules:

dep ensure -add github.com/fabienm/go-logrus-formatters

or

go get github.com/fabienm/go-logrus-formatters

GELF formatter

The GELF formatter supports 1.1 payload specification.

Notable features:

  • Logrus levels are converted to syslog levels
  • Logrus entries times are converted to UNIX timestamps.
  • Logrus entry fields are prefixed with _, excepted version, host, short_message, full_message, timestamp and level, allowing override.

Syslog level mapping

Logrus Syslog
Panic EMERG (0)
Fatal CRIT (2)
Error ERR (3)
Warn WARNING (4)
Info INFO (6)
Debug DEBUG (7)

Usage

package main

import (
	"os"

	"github.com/fabienm/go-logrus-formatters"
	log "github.com/sirupsen/logrus"
)

func init() {
	hostname, _ := os.Hostname()
	// Log as GELF instead of the default ASCII formatter.
	log.SetFormatter(formatters.NewGelf(hostname))
}

func main() {
	log.WithFields(log.Fields{
		"animal": "walrus",
		"size":   10,
	}).Info("A group of walrus emerges from the ocean")
	log.WithFields(log.Fields{
		"full_message":  "Backtrace here\n\nmore stuff",
		"user_id":      9001,
		"some_info":    "foo",
		"some_env_var": "bar",
	}).Fatal("A short message that helps you identify what is going on")
}

Output:

{"_animal":"walrus","_level_name":"INFORMATIONAL","_size":10,"host":"mylaptop","level":6,"short_message":"A group of walrus emerges from the ocean","timestamp":1522937330.7570872,"version":"1.1"}
{"_some_env_var":"bar","_some_info":"foo","_user_id":9001,"_level_name":"CRITICAL","full_message":"Backtrace here\n\nmore stuff","host":"mylaptop","level":2,"short_message":"A short message that helps you identify what is going on","timestamp":1522937330.7573297,"version":"1.1"}

See also

go-logrus-formatters's People

Contributors

fabienm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.