Skip to content
elad-aharonPublic
forked from sjones4/zap-gelf

About

Zap GELF

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

21 Commits

Folders and files

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")
}

About

Zap GELF

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages