log

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

README

log

Go logging library used at Mailgun.

Usage

Define a logging configuration in a YAML config file. Currently "console" and "syslog" loggers are supported (you can omit one or another):

logging:
  - name: console
  - name: syslog

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

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.Init(conf.Logging)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs to the ERROR, WARNING, and INFO logs.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).

func Infof

func Infof(format string, args ...interface{})

Infof logs to the INFO log.

func Init

func Init(logConfigs []*LogConfig) error

Loggin initialization, must be called at the beginning of your cool app.

func SetSeverity

func SetSeverity(s Severity)

SetSeverity sets current logging severity. Acceptable values are SeverityInfo, SeverityWarn, SeverityError, SeverityFatal

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs to the WARNING and INFO logs.

Types

type LogConfig

type LogConfig struct {
	Name string
}

Logging configuration to be passed to all loggers during initialization.

type Logger

type Logger interface {
	Info(string)
	Warning(string)
	Error(string)
	Fatal(string)
}

Logger is a unified interface for all loggers.

func NewConsoleLogger

func NewConsoleLogger(config *LogConfig) (Logger, error)

func NewSysLogger

func NewSysLogger(config *LogConfig) (Logger, error)

type Severity

type Severity int32

Severity implementation is borrowed from glog, uses sync/atomic int32

const (
	SeverityInfo Severity = iota
	SeverityWarn
	SeverityError
	SeverityFatal
)

func GetSeverity

func GetSeverity() Severity

GetSeverity returns currently set severity.

func SeverityFromString

func SeverityFromString(s string) (Severity, error)

func (*Severity) Get

func (s *Severity) Get() Severity

get returns the value of the severity.

func (*Severity) Gt

func (s *Severity) Gt(val Severity) bool

less returns if this severity is greater than passed severity

func (*Severity) Set

func (s *Severity) Set(val Severity)

set sets the value of the severity.

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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