gelf

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 10 Imported by: 15

README

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

Documentation

Overview

Package gelf added availability to zap logger send your logs to Graylog server over UDP.

Index

Constants

View Source
const (
	// MinChunkSize minimal chunk size in bytes.
	MinChunkSize = 512

	// MaxChunkSize maximal chunk size in bytes.
	// See http://docs.graylog.org/en/2.4/pages/gelf.html.
	MaxChunkSize = 8192

	// MaxChunkCount maximal chunk per message count.
	// See http://docs.graylog.org/en/2.4/pages/gelf.html.
	MaxChunkCount = 128

	// DefaultChunkSize is default WAN chunk size.
	DefaultChunkSize = 1420

	// CompressionNone don't use compression.
	CompressionNone = 0

	// CompressionGzip use gzip compression.
	CompressionGzip = 1

	// CompressionZlib use zlib compression.
	CompressionZlib = 2
)

Variables

View Source
var (
	// ErrChunkTooSmall triggered when chunk size to small.
	ErrChunkTooSmall = errors.New("chunk size too small")

	// ErrChunkTooLarge triggered when chunk size too large.
	ErrChunkTooLarge = errors.New("chunk size too large")

	// ErrUnknownCompressionType triggered when passed invalid compression type.
	ErrUnknownCompressionType = errors.New("unknown compression type")
)

Functions

func NewCore

func NewCore(options ...Option) (_ zapcore.Core, err error)

NewCore zap core constructor.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option interface.

func Addr

func Addr(value string) Option

Addr set GELF address.

func CallerKey

func CallerKey(value string) Option

CallerKey set zapcore.EncoderConfig CallerKey property.

func ChunkSize

func ChunkSize(value int) Option

ChunkSize set GELF chunk size.

func CompressionLevel

func CompressionLevel(value int) Option

CompressionLevel set GELF compression level.

func CompressionType

func CompressionType(value int) Option

CompressionType set GELF compression type.

func EncodeCaller

func EncodeCaller(value zapcore.CallerEncoder) Option

EncodeCaller set zapcore.EncoderConfig EncodeCaller property.

func EncodeDuration

func EncodeDuration(value zapcore.DurationEncoder) Option

EncodeDuration set zapcore.EncoderConfig EncodeDuration property.

func EncodeName

func EncodeName(value zapcore.NameEncoder) Option

EncodeName set zapcore.EncoderConfig EncodeName property.

func FunctionKey added in v1.1.0

func FunctionKey(value string) Option

FunctionKey set zapcore.EncoderConfig FunctionKey property.

func Host

func Host(value string) Option

Host set GELF host.

func Level

func Level(value zapcore.Level) Option

Level set logging level.

func LevelAtomic added in v1.3.0

func LevelAtomic(level zap.AtomicLevel) Option

LevelAtomic set atomic logging level which can be changed dynamically.

func LevelKey added in v1.1.0

func LevelKey(value string) Option

LevelKey set zapcore.EncoderConfig LevelKey property.

func LevelString

func LevelString(value string) Option

LevelString set logging level.

func LineEnding

func LineEnding(value string) Option

LineEnding set zapcore.EncoderConfig LineEnding property.

func MessageKey added in v1.1.0

func MessageKey(value string) Option

MessageKey set zapcore.EncoderConfig MessageKey property.

func NameKey

func NameKey(value string) Option

NameKey set zapcore.EncoderConfig NameKey property.

func NewReflectedEncoder added in v1.1.0

func NewReflectedEncoder(value func(io.Writer) zapcore.ReflectedEncoder) Option

NewReflectedEncoder set zapcore.EncoderConfig NewReflectedEncoder property.

func SkipLineEnding added in v1.1.0

func SkipLineEnding(value bool) Option

SkipLineEnding set zapcore.EncoderConfig SkipLineEnding property.

func StacktraceKey added in v1.1.0

func StacktraceKey(value string) Option

StacktraceKey set zapcore.EncoderConfig StacktraceKey property.

func TimeKey added in v1.1.0

func TimeKey(value string) Option

TimeKey set zapcore.EncoderConfig TimeKey property.

func Version

func Version(value string) Option

Version set GELF version.

func WriteSyncers added in v1.2.0

func WriteSyncers(value ...zapcore.WriteSyncer) Option

WriteSyncers sets additional zapcore.WriteSyncers on the core.

Jump to

Keyboard shortcuts

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