Gelf Logger
Go to file
Stefan Goppelt a665b7264c
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
ci: fix release-notes for tag builds
2026-03-29 18:03:42 +02:00
.githooks Add project standards files and scripts for consistency 2026-03-29 17:36:47 +02:00
docs Enhance CI pipeline and documentation 2026-03-29 17:53:05 +02:00
scripts ci: fix release-notes for tag builds 2026-03-29 18:03:42 +02:00
.drone.yml ci: fix release-notes for tag builds 2026-03-29 18:03:42 +02:00
.editorconfig Add project standards files and scripts for consistency 2026-03-29 17:36:47 +02:00
.gitattributes Add project standards files and scripts for consistency 2026-03-29 17:36:47 +02:00
.gitignore Add project standards files and scripts for consistency 2026-03-29 17:36:47 +02:00
AGENTS.md Enhance CI pipeline and documentation 2026-03-29 17:53:05 +02:00
CHANGELOG.md docs: add changelog for upcoming v0.0.3 2026-03-29 17:57:44 +02:00
LICENSE Initial commit 2022-04-05 08:47:56 +00:00
README.md Enhance CI pipeline and documentation 2026-03-29 17:53:05 +02:00
gelflogger.go Updated libraries, add build and update README 2023-03-08 10:27:38 +01:00
gelflogger_test.go Enhance CI pipeline and documentation 2026-03-29 17:53:05 +02:00
go.mod Enhance CI pipeline and documentation 2026-03-29 17:53:05 +02:00
go.sum Enhance CI pipeline and documentation 2026-03-29 17:53:05 +02:00

README.md

Go GELF Logging Library

yoorie favicon

Build Status

Minimal helper package to send application logs to Graylog via GELF while still writing to the standard Go logger.

Overview

This module wraps gopkg.in/aphistic/golf.v0 and exposes a small API for common log levels.

Behavior summary:

  • If GELF is configured with SetDefaultConfig, messages are sent to Graylog over UDP.
  • Messages are also written to the standard Go logger (log package).
  • If GELF is not configured, logging still works locally via the standard logger.

Installation

go get scm.yoorie.de/go-lib/gelf

Quick Start

package main

import (
  "scm.yoorie.de/go-lib/gelf"
)

func main() {
  gelf.SetDefaultConfig("graylog.example.local", 12201,
    map[string]interface{}{
      "service": "billing-api",
      "env":     "prod",
    },
  )

  gelf.Info("service started")
  gelf.Infof("listening on %s", ":8080")
  gelf.Alert("database latency is high")
}

API

Configuration

  • SetDefaultConfig(host string, port int, attrs map[string]interface{})

Creates and configures the default GELF logger. Attributes in attrs are attached as default fields to all GELF messages.

Logging Functions

  • Debug(msg string)
  • Debugf(format string, va ...interface{})
  • Info(msg string)
  • Infof(format string, va ...interface{})
  • Alert(msg string)
  • Alertf(format string, va ...interface{})
  • Fatal(msg string)
  • Fatalf(format string, va ...interface{})

Notes

  • Fatal and Fatalf terminate the program by calling log.Fatalf.
  • Graylog delivery uses UDP (udp://host:port).
  • Calling SetDefaultConfig again replaces the previous client.

Development

Run tests:

go test ./...

Module information is defined in go.mod.

Additional Documentation

License

See LICENSE.


Copyright © 2023 yoorie.de