golog

package module
v0.0.0-...-396f5a9 Latest Latest
Warning

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

Go to latest
Published: May 9, 2014 License: MIT Imports: 5 Imported by: 0

README

golog

The package is logging library for Go.

Features

  • Multiple backends: io.Writer, os.Stderr/os.Stdout, log/syslog.
  • Multiple chained formatters: Noop, Color, Newline, etc.
  • Each backend can have own formatter and severity mask.

How to install

go get github.com/antage/golog

Usage

package main

import (
    "github.com/antage/golog"
)

var log golog.Logger

func init() {
    log = golog.NewLogger()

    log.AddBackend(
        golog.ERROR,
        golog.DefaultConsoleFormatter(),
        golog.NewConsoleBackend())

    syslog, err := golog.NewSyslogBackend(golog.SYSLOG_LOCAL0, "exampled")
    if err != nil {
        panic(err.Error())
    }

    log.AddBackend(
        golog.ERROR | golog.INFO,
        golog.NoopFormatter{},
        syslog)
}

func main() {
    x := 1
    log.Debugf("x = %d", x)
    log.Infof("x has value %d", x)
    log.Errorf("some error")
    log.Fatalf("some error and os.Exit(1)")
}

Documentation

http://godoc.org/github.com/antage/golog

License

See LICENSE file.

Documentation

Overview

The golog package implements logging to multiple backends. Each backend can filter messages by severity mask and have custom formatter. The package includes io.Writer, console and syslog backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Error(msg string)
	Warning(msg string)
	Info(msg string)
	Debug(msg string)
}

func NewConsoleBackend

func NewConsoleBackend() Backend

func NewSyslogBackend

func NewSyslogBackend(facility Facility, tag string) (Backend, error)

func NewWriterBackend

func NewWriterBackend(writer io.Writer) Backend

type ChainedFormatter

type ChainedFormatter struct {
	// contains filtered or unexported fields
}

func (ChainedFormatter) FormatDebug

func (formatter ChainedFormatter) FormatDebug(msg string) string

func (ChainedFormatter) FormatError

func (formatter ChainedFormatter) FormatError(msg string) string

func (ChainedFormatter) FormatInfo

func (formatter ChainedFormatter) FormatInfo(msg string) string

func (ChainedFormatter) FormatWarning

func (formatter ChainedFormatter) FormatWarning(msg string) string

type ColorFormatter

type ColorFormatter struct{}

func (ColorFormatter) FormatDebug

func (formatter ColorFormatter) FormatDebug(msg string) string

func (ColorFormatter) FormatError

func (formatter ColorFormatter) FormatError(msg string) string

func (ColorFormatter) FormatInfo

func (formatter ColorFormatter) FormatInfo(msg string) string

func (ColorFormatter) FormatWarning

func (formatter ColorFormatter) FormatWarning(msg string) string

type Facility

type Facility int
const (

	// From /usr/include/sys/syslog.h.
	// These are the same up to LOG_FTP on Linux, BSD, and OS X.
	SYSLOG_KERN Facility = iota << 3
	SYSLOG_USER
	SYSLOG_MAIL
	SYSLOG_DAEMON
	SYSLOG_AUTH
	SYSLOG_SYSLOG
	SYSLOG_LPR
	SYSLOG_NEWS
	SYSLOG_UUCP
	SYSLOG_CRON
	SYSLOG_AUTHPRIV
	SYSLOG_FTP

	SYSLOG_LOCAL0
	SYSLOG_LOCAL1
	SYSLOG_LOCAL2
	SYSLOG_LOCAL3
	SYSLOG_LOCAL4
	SYSLOG_LOCAL5
	SYSLOG_LOCAL6
	SYSLOG_LOCAL7
)

type Formatter

type Formatter interface {
	FormatError(msg string) string
	FormatWarning(msg string) string
	FormatInfo(msg string) string
	FormatDebug(msg string) string
}

func DefaultConsoleFormatter

func DefaultConsoleFormatter() Formatter

func NewChainedFormatter

func NewChainedFormatter(formatters ...Formatter) Formatter

type Logger

type Logger interface {
	AddBackend(mask Severity, formatter Formatter, backend Backend)

	Errorf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})

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

func NewLogger

func NewLogger() Logger

type NewlineFormatter

type NewlineFormatter struct{}

func (NewlineFormatter) FormatDebug

func (formatter NewlineFormatter) FormatDebug(msg string) string

func (NewlineFormatter) FormatError

func (formatter NewlineFormatter) FormatError(msg string) string

func (NewlineFormatter) FormatInfo

func (formatter NewlineFormatter) FormatInfo(msg string) string

func (NewlineFormatter) FormatWarning

func (formatter NewlineFormatter) FormatWarning(msg string) string

type NoopFormatter

type NoopFormatter struct{}

func (NoopFormatter) FormatDebug

func (_ NoopFormatter) FormatDebug(msg string) string

func (NoopFormatter) FormatError

func (_ NoopFormatter) FormatError(msg string) string

func (NoopFormatter) FormatInfo

func (_ NoopFormatter) FormatInfo(msg string) string

func (NoopFormatter) FormatWarning

func (_ NoopFormatter) FormatWarning(msg string) string

type Severity

type Severity int
const (
	ERROR Severity = 1 << iota
	WARNING
	INFO
	DEBUG
	ALL Severity = ^0
)

Jump to

Keyboard shortcuts

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