gelf

package module
v0.0.0-...-a1ad77c Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: MIT Imports: 9 Imported by: 0

README

zap-graylog-writer

Writes log messages from go.uber.org/zap to GELF input (as provided by graylog2, ELK stack, etc.). Code for feeding data into gelf sink has been taken from github.com/robertkowalski/graylog-golang.

A complete example for setting up zap with gelf data sink:

package main

import (
    "os"
    "path"

    "github.com/c-atarella/zap-graylog-writer"
    "go.uber.org/zap"
)

const (
    appVersion = "0.0.1"
)

var baseLogger *zap.Logger

func init() {
    core, fieldsOption := gelf.NewGelfCore("192.168.1.6", "my_fancy_app",
        zap.Int("_pid", os.Getpid()),
        zap.String("_exe", path.Base(os.Args[0])),
        zap.String("_appversion", appVersion))
    baseLogger = zap.New(core, fieldsOption)
    defer baseLogger.Sync()

}

func main() {
    for i := 0; i < 10; i++ {
        baseLogger.Info("huh jo", zap.Int("MessageId", i))
    }
}

Notes

  • currently compression is not supported!
  • no safety checks for invalid fields!
  • use at your own risk :)
  • tested with graylog-2.2.3

Documentation

Index

Constants

View Source
const (
	// VersionTag is mandatory
	VersionTag = "version"
	// Version of supported gelf format
	Version = "1.1"
	// HostTag is mandatory
	HostTag = "host"
	// LevelTag is mandatory
	LevelTag = "level"
	// MessageKey provides the key value for gelf message field
	MessageKey = "short_message"
	TimeKey    = "timestamp"
)

Variables

This section is empty.

Functions

func New

func New(config Config) zapcore.WriteSyncer

New returns an implementation of ZapWriteSyncer which should be compatible with zap.WriteSyncer

func NewGelfCore

func NewGelfCore(host string, appOrHostName string, fs ...zapcore.Field) (zapcore.Core, zap.Option)

func SyslogLevelEncoder

func SyslogLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

ZapLevelToGelfLevel maps the zap log levels to the syslog severity levels used for gelf. See https://en.wikipedia.org/wiki/Syslog for details.

Types

type Config

type Config struct {
	GraylogPort     int
	GraylogHostname string
	MaxChunkSize    int
}

Config represents the required settings for connecting the gelf data sink.

func NewDefaultConfig

func NewDefaultConfig(host string) Config

NewDefaultConfig provides a configuration with default values for port and chunk size.

Jump to

Keyboard shortcuts

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