Skip to content

snovichkov/zap-gelf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zap GELF GitHub license Go Report Card Build Status Coverage Status GoDoc

Zap GELF added availability to zap logger send your logs to Graylog server over UDP. All zap fields will be sent as additional fields on Graylog.

Installation

go get -u github.com/snovichkov/zap-gelf

Features

  • Use fast zap JSON serializer
  • Support chunking over UPD
  • Support gzip/zlib compression

Quick Start

package main 

import (
	"os"
	
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
	"github.com/snovichkov/zap-gelf"
)

func main() {
	var (
        err  error
        host string
        core zapcore.Core
    )
    
    if host, err = os.Hostname(); err != nil {
        panic(err)
    }
    
    if core, err = gelf.NewCore(
        gelf.Addr("127.0.0.1:12001"),
        gelf.Host(host),
    ); err != nil {
        panic(err)
    }
    
    var logger = zap.New(
        core,
        zap.AddCaller(),
        zap.AddStacktrace(zap.LevelEnablerFunc(func(l zapcore.Level) bool {
            return core.Enabled(l)
        })),
    )
    defer logger.Sync()
    
    logger.
        With(
            zap.String("with", "field"),
        ).
        Error(
            "An error was accrued",
            zap.String("an_filed", "Hello word!"),
            zap.String("id", "an_id"),
        )
    
    logger.
        Sugar().
        With(
            "an_filed", "Hello word!",
            "id", "an_id",
        ).
        Error("An error was accrued")
}