Documentation ¶
Overview ¶
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 ¶
- Variables
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func Register()
- func SetLevel(level Level)
- func SetLogger(logger Logger)
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
- type BaseLogger
- type Level
- type Logger
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs at the debug level with the semantics of fmt.Printf.
func Debugln ¶
func Debugln(args ...interface{})
Debugln logs at the debug level with the semantics of fmt.Println.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs at the error level with the semantics of fmt.Printf.
func Errorln ¶
func Errorln(args ...interface{})
Errorln logs at the error level with the semantics of fmt.Println.
func Fatalf ¶
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 ¶
func Fatalln(args ...interface{})
Fatalln logs at the fatal level with the semantics of fmt.Println and exits with os.Exit(1).
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs at the info level with the semantics of fmt.Printf.
func Infoln ¶
func Infoln(args ...interface{})
Infoln logs at the info level with the semantics of fmt.Println.
func Panicf ¶
func Panicf(format string, args ...interface{})
Panicf logs at the panic level with the semantics of fmt.Printf and panics.
func Panicln ¶
func Panicln(args ...interface{})
Panicln logs at the panic level with the semantics of fmt.Println and panics.
func Printf ¶
func Printf(format string, args ...interface{})
Printf logs at the info level with the semantics of fmt.Printf.
func Println ¶
func Println(args ...interface{})
Println logs at the info level with the semantics of fmt.Println.
func Warnf ¶
func Warnf(format string, args ...interface{})
Warnf logs at the warn level with the semantics of fmt.Printf.
func Warnln ¶
func Warnln(args ...interface{})
Warnln logs at the warn level with the semantics of fmt.Println.
Types ¶
type BaseLogger ¶
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 ¶
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 ¶
NameToLevel returns the Level for the given name.
type Logger ¶
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 ¶
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 ¶
NewStdLogger creates a new Logger using a standard golang Logger.
func WithField ¶
WithField calls WithField on the global Logger.
Directories ¶
Path | Synopsis |
---|---|
Package dlog_glog provides glog functionality for dlog.
|
Package dlog_glog provides glog functionality for dlog. |
Package dlog_lion provides lion functionality for dlog.
|
Package dlog_lion provides lion functionality for dlog. |
Package dlog_log15 provides log15 functionality for dlog.
|
Package dlog_log15 provides log15 functionality for dlog. |
Package dlog_logrus provides logrus functionality for dlog.
|
Package dlog_logrus provides logrus functionality for dlog. |
Package dlog_testing provides very basic testing for dlog.
|
Package dlog_testing provides very basic testing for dlog. |
Package dlog_zap provides zap functionality for dlog.
|
Package dlog_zap provides zap functionality for dlog. |