dlog: go.pedge.io/dlog Index | Files | Directories

package dlog

import "go.pedge.io/dlog"

Package dlog (delegating log) wraps common functionality for common golang logging packages.

The Logger interface wraps the common logging functionality. Every method on Logger is also a global method on the dlog package. Given an implementation of Logger, you can register it as the global logger by calling:

func register(logger dlog.Logger) {
  dlog.SetLogger(logger)
}

To make things simple, packages for glog, logrus, log15, and lion are given with the ability to easily register their implementations as the default logger:

import (
  "go.pedge.io/dlog/glog"
  "go.pedge.io/dlog/lion"
  "go.pedge.io/dlog/log15"
  "go.pedge.io/dlog/logrus"
)

func registrationFunctions() {
  dlog_glog.Register() // set glog as the global logger
  dlog_lion.Register() // set lion as the global logger with default settings
  dlog_log15.Register() // set log15 as the global logger with default settings
  dlog_logrus.Register() // set logrus as the global logger with default settings
}

Or, do something more custom:

import (
  "os"

  "go.pedge.io/dlog"
  "go.pedge.io/dlog/logrus"

  "github.com/Sirupsen/logrus"
)

func init() { // or anywhere
  logger := logrus.New()
  logger.Out = os.Stdout
  logger.Formatter = &logrus.TextFormatter{
	ForceColors: true,
  }
  dlog.SetLogger(dlog_logrus.NewLogger(logger))
}

By default, golang's standard logger is used. This is not recommended, however, as the implementation with the WithFields function is slow. It would be better to choose a different implementation in most cases.

Index

Package Files

dlog.go dlog_level.go

Variables

var (
    // DefaultLogger is the default Logger.
    DefaultLogger = NewStdLogger(log.New(os.Stderr, "", log.LstdFlags))
    // DefaultLevel is the default Level.
    DefaultLevel = LevelInfo
)

func Debugf Uses

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

Debugf logs at the debug level with the semantics of fmt.Printf.

func Debugln Uses

func Debugln(args ...interface{})

Debugln logs at the debug level with the semantics of fmt.Println.

func Errorf Uses

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

Errorf logs at the error level with the semantics of fmt.Printf.

func Errorln Uses

func Errorln(args ...interface{})

Errorln logs at the error level with the semantics of fmt.Println.

func Fatalf Uses

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

Fatalf logs at the fatal level with the semantics of fmt.Printf and exits with os.Exit(1).

func Fatalln Uses

func Fatalln(args ...interface{})

Fatalln logs at the fatal level with the semantics of fmt.Println and exits with os.Exit(1).

func Infof Uses

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

Infof logs at the info level with the semantics of fmt.Printf.

func Infoln Uses

func Infoln(args ...interface{})

Infoln logs at the info level with the semantics of fmt.Println.

func Panicf Uses

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

Panicf logs at the panic level with the semantics of fmt.Printf and panics.

func Panicln Uses

func Panicln(args ...interface{})

Panicln logs at the panic level with the semantics of fmt.Println and panics.

func Printf Uses

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

Printf logs at the info level with the semantics of fmt.Printf.

func Println Uses

func Println(args ...interface{})

Println logs at the info level with the semantics of fmt.Println.

func Register Uses

func Register()

Register re-registers the default Logger as the dlog global Logger.

func SetLevel Uses

func SetLevel(level Level)

SetLevel sets the global Level.

func SetLogger Uses

func SetLogger(logger Logger)

SetLogger sets the global logger used by dlog.

func Warnf Uses

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

Warnf logs at the warn level with the semantics of fmt.Printf.

func Warnln Uses

func Warnln(args ...interface{})

Warnln logs at the warn level with the semantics of fmt.Println.

type BaseLogger Uses

type BaseLogger interface {
    Debugf(format string, args ...interface{})
    Debugln(args ...interface{})
    Infof(format string, args ...interface{})
    Infoln(args ...interface{})
    Warnf(format string, args ...interface{})
    Warnln(args ...interface{})
    Errorf(format string, args ...interface{})
    Errorln(args ...interface{})
    Fatalf(format string, args ...interface{})
    Fatalln(args ...interface{})
    Panicf(format string, args ...interface{})
    Panicln(args ...interface{})
    Printf(format string, args ...interface{})
    Println(args ...interface{})
}

BaseLogger is the Logger's log functionality, split from WithField/WithFields for easier wrapping of other libraries.

type Level Uses

type Level int32

Level is a logging level.

const (
    // LevelNone represents no Level.
    LevelNone Level = 0
    // LevelDebug is the debug Level.
    LevelDebug Level = 1
    // LevelInfo is the info Level.
    LevelInfo Level = 2
    // LevelWarn is the warn Level.
    LevelWarn Level = 3
    // LevelError is the error Level.
    LevelError Level = 4
    // LevelFatal is the fatal Level.
    LevelFatal Level = 5
    // LevelPanic is the panic Level.
    LevelPanic Level = 6
)

func NameToLevel Uses

func NameToLevel(name string) (Level, error)

NameToLevel returns the Level for the given name.

func (Level) String Uses

func (l Level) String() string

String returns the name of a Level or the numerical value if the Level is unknown.

type Logger Uses

type Logger interface {
    BaseLogger
    AtLevel(level Level) Logger
    WithField(key string, value interface{}) Logger
    WithFields(fields map[string]interface{}) Logger
}

Logger is an interface that all logging implementations must implement.

func NewLogger Uses

func NewLogger(printFunc func(...interface{}), levelToPrintFunc map[Level]func(...interface{})) Logger

NewLogger creates a new Logger using a print function, and optionally specific Level to print functions (levelToPrintFunc can be nil).

printFunc is used if a Level is not represented. LevelNone overrides printFunc.

printFunc is required.

func NewStdLogger Uses

func NewStdLogger(l *log.Logger) Logger

NewStdLogger creates a new Logger using a standard golang Logger.

func WithField Uses

func WithField(key string, value interface{}) Logger

WithField calls WithField on the global Logger.

func WithFields Uses

func WithFields(fields map[string]interface{}) Logger

WithFields calls WithFields on the global Logger.

Directories

PathSynopsis
glogPackage dlog_glog provides glog functionality for dlog.
lionPackage dlog_lion provides lion functionality for dlog.
log15Package dlog_log15 provides log15 functionality for dlog.
logrusPackage dlog_logrus provides logrus functionality for dlog.
testingPackage dlog_testing provides very basic testing for dlog.
zapPackage dlog_zap provides zap functionality for dlog.

Package dlog imports 7 packages (graph) and is imported by 30 packages. Updated 2017-04-25. Refresh now. Tools for package owners.