zerologgelfoutput package - github.com/DreamDevLost/zerolog-gelf-output - Go Packages

zerologgelfoutput

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

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 6 Imported by: 0

README

zerolog-gelf-output

The zerolog-gelf-output module is designed to seamlessly integrate with Go's popular zerolog logging library, enabling applications to redirect their JSON log outputs to a GELF-compatible server such as Graylog. This allows for more structured and centralized logging, making it easier to monitor and analyze logs in real-time.

Features

  • Easy Integration: Works out of the box with the zerolog logger.
  • GELF Support: Fully compatible with the GELF (Graylog Extended Log Format) specification.

Getting Started

Prerequisites
  • Go 1.15 or later
  • A GELF-compatible server (e.g., Graylog) accessible over the network
Installation

To install zerolog-gelf-output, use the go get command:

go get github.com/DreamDevLost/zerolog-gelf-output
Usage

Here is a basic example of how to use zerolog-gelf-output in your Go application:

package main

import (
    "github.com/rs/zerolog"
    zerologgelfoutput "github.com/DreamDevLost/zerolog-gelf-output"
)

func main() {
    // Configure the GELF writer
    gelfWriter, err := zerologgelfoutput.NewWithPassthrough("udp://localhost:12201", "app-name", "environment", "v1.0.0", zerolog.ConsoleWriter{Out: os.Stdout})
    if err != nil {
        panic("Failed to create GELF writer: " + err.Error())
    }

    // Create a new zerolog logger with the GELF writer
    log := zerolog.New(gelfWriter).With().Timestamp().Logger()

    // Log a message as you normally would
    log.Info().Str("info1", "info1").Int("info2", 2).Msg("This is a test message sent to GELF server")
}

Contributing

We welcome contributions! If you'd like to contribute, please follow the guidelines outlined in CONTRIBUTING.md.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(addr, appName, env, version string) (io.WriteCloser, error)

New creates a new io.WriteCloser that sends logs to a GELF server at the given address.

func NewWithPassthrough

func NewWithPassthrough(addr, appName, env, version string, passthrough io.Writer) (io.WriteCloser, error)

NewWithPassthrough creates a new io.WriteCloser that sends logs to a GELF server at the given address and also writes the logs to the given passthrough writer.

This is useful for debugging, as it allows you to see the logs that are being sent to the GELF server. If you don't need this, use New instead.

example:

w, err := NewWithPassthrough("localhost:12201", "myapp", "dev", "1.0.0", os.Stdout)
if err != nil {
	...
}

OR

w, err := NewWithPassthrough("localhost", "myapp", "dev", "1.0.0", zerolog.ConsoleWriter{Out: os.Stdout}))
if err != nil {
	...
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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