Categorygithub.com/mailgun/log
modulepackage
0.0.0-20150926000944-2f35a4607f1a
Repository: https://github.com/mailgun/log.git
Documentation: pkg.go.dev

# README

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

# Functions

Debugf logs to the DEBUG log.
Errorf logs to the ERROR, WARN, and INFO logs.
No description provided by the author
Infof logs to the INFO log.
Init initializes the logging package with the provided loggers.
InitWithConfig instantiates loggers based on the provided configs and initializes the package with them.
Logfmt logs a formatted message of the specified severity, marking it attributed to a function at the specified depth on the current goroutine stack.
No description provided by the author
NewLogger makes a proper logger from the given configuration.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Warningf logs to the WARN and INFO logs.

# Constants

Supported log types.
No description provided by the author
No description provided by the author
No description provided by the author
Supported severities.
Supported severities.
Supported severities.
Supported severities.
Supported log types.
Supported log types.

# Structs

CallerInfo encapsulates information about a piece of code that called a certain log function, such as file name, line number, etc.
Config represents a configuration of an individual logger.

# Interfaces

Logger is an interface that should be implemented by all loggers wishing to participate in the logger chain initialized by this package.
No description provided by the author

# Type aliases

No description provided by the author