Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 29 commits ahead of DECK36:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Support for EditorConfig (#14) Jul 28, 2017
.gitignore ignore IDE files Aug 2, 2016
.travis.yml Add Travis CI support (#15) Jul 28, 2017
LICENSE add license Oct 31, 2012
README.md Syntax Highlighting (#17) Aug 11, 2017


go-gelf - GELF Library and Writer for Go

GELF (Graylog Extended Log Format) is an application-level logging protocol that avoids many of the shortcomings of syslog. While it can be run over any stream or datagram transport protocol, it has special support (chunking) to allow long messages to be split over multiple datagrams.


In order to enable versionning of this package with Go, this project is using GoPkg.in. The default branch of this project will be v1 for some time to prevent breaking clients. We encourage all project to change their imports to the new GoPkg.in URIs as soon as possible.

To see up to date code, make sure to switch to the master branch.


This implementation currently supports only UDP as a transport protocol. TCP and TLS are unsupported.

The library provides an API that applications can use to log messages directly to a Graylog server and an io.Writer that can be used to redirect the standard library's log messages (os.Stdout) to a Graylog server.


go-gelf is go get-able:

go get gopkg.in/Graylog2/go-gelf.v1/gelf


go get github.com/Graylog2/go-gelf/gelf

This will get you version 1.0.0, with only UDP support and legacy API. Newer versions are available through GoPkg.in:

go get gopkg.in/Graylog2/go-gelf.v2/gelf


The easiest way to integrate graylog logging into your go app is by having your main function (or even init) call log.SetOutput(). By using an io.MultiWriter, we can log to both stdout and graylog - giving us both centralized and local logs. (Redundancy is nice).

package main

import (

func main() {
	var graylogAddr string

	flag.StringVar(&graylogAddr, "graylog", "", "graylog server addr")

	if graylogAddr != "" {
		gelfWriter, err := gelf.NewWriter(graylogAddr)
		if err != nil {
			log.Fatalf("gelf.NewWriter: %s", err)
		// log to both stderr and graylog2
		log.SetOutput(io.MultiWriter(os.Stderr, gelfWriter))
		log.Printf("logging to stderr & graylog2@'%s'", graylogAddr)

	// From here on out, any calls to log.Print* functions
	// will appear on stdout, and be sent over UDP to the
	// specified Graylog2 server.

	log.Printf("Hello gray World")

	// ...

The above program can be invoked as:

go run test.go -graylog=localhost:12201

When using UDP messages may be dropped or re-ordered. However, Graylog server availability will not impact application performance; there is a small, fixed overhead per log call regardless of whether the target server is reachable or not.

To Do

  • WriteMessage example


go-gelf is offered under the MIT license, see LICENSE for details.