Skip to content
mailgunPublic

About

Go logging library used at Mailgun.

Resources

Stars

20 stars

Watchers

19 watching

Forks

Repository files navigation

log

Go logging library used at Mailgun.

Usage

The mailgun/log package supports chains of loggers where the same message can go to multiple logging channels simultaneously, for example, the standard output and syslog.

Currently, the following loggers are supported: console (stdout), syslog and updlog. The latter requires having udplog server (https://github.com/mochi/udplog) running locally. Custom loggers can implement the package's Logger interface and be intergated into the logger chain.

Before using the package it should be initialized at the start of a program. It can be done in two ways.

Initialize with loggers

import "github.com/mailgun/log"

func main() {
  // create a console logger
  console, _ := log.NewLogger(log.Config{"console", "info"})

  // create a syslogger
  syslog, _ := log.NewLogger(log.Config{"syslog", "error"})

  // init the logging package
  log.Init(console, syslog) // or any other logger implementing `log.Logger` can be provided
}

Initialize with a config

Mailgun's cfg package (https://github.com/mailgun/cfg) simplifies this method.

Define a logging configuration in a YAML config file.

logging:
  - name:     console
    severity: error
  - name:     syslog
    severity: info

Logging config can be built into your program's config struct:

import "github.com/mailgun/log"

type Config struct {
  // some program-specific configuration

  // logging configuration
  Logging []log.Config
}

After config parsing, initialize the logging library:

import (
  "github.com/mailgun/cfg"
  "github.com/mailgun/log"
)

func main() {
  conf := Config{}

  // parse config with logging configuration
  cfg.LoadConfig("path/to/config.yaml", &conf)

  // init the logging package
  log.InitWithConfig(conf.Logging...)
}

About

Go logging library used at Mailgun.

Resources

Stars

20 stars

Watchers

19 watching

Forks

Releases

Packages

Used by

Contributors

Languages