gooseberry: github.com/voicera/gooseberry/log Index | Examples | Files | Directories

package log

import "github.com/voicera/gooseberry/log"

Package log provides a logger interface so that logging in gooseberry is pluggable; gooseberry provides a wrapper for https://go.uber.org/zap that implements said interface. See package log/zap.

Index

Examples

Package Files

doc.go log.go

type LeveledLogger Uses

type LeveledLogger interface {
    // IsDebugEnabled checks whether or not debug logging is enabled.
    // Useful to check before logging a message that requires preprocessing.
    IsDebugEnabled() bool

    // Debug logs a debug message.
    // It accepts varargs of alternating key and value parameters.
    Debug(message string, args ...interface{})

    // Info logs a informational message.
    // It accepts varargs of alternating key and value parameters.
    Info(message string, args ...interface{})

    // Warn logs a warning message.
    // It accepts varargs of alternating key and value parameters.
    Warn(message string, args ...interface{})

    // Error logs an error message.
    // It accepts varargs of alternating key and value parameters.
    Error(message string, args ...interface{})

    // Sync flushes the logger.
    Sync() error
}

LeveledLogger provides a logging interface that supports structured logging. For example:

logger.Info("Found an answer.", "answer", 42)
logger.Debug("message", "key", value, "another key", anotherValue)

Code:

logger := NewPrefixedLeveledLogger(&testutil.Logger{InDebugMode: true}, "prefix:")
fmt.Println("IsDebugEnabled:", logger.IsDebugEnabled())
logger.Debug("message", "answer", 42)
logger.Info("message", "answer", 42)
logger.Warn("message", "answer", 42)
logger.Error("message", "answer", 42)

Output:

IsDebugEnabled: true
[Debug] prefix:message: [answer 42]
[Info] prefix:message: [answer 42]
[Warn] prefix:message: [answer 42]
[Error] prefix:message: [answer 42]

func NewPrefixedLeveledLogger Uses

func NewPrefixedLeveledLogger(logger LeveledLogger, prefix string) LeveledLogger

NewPrefixedLeveledLogger prepends a prefix to log messages logged by the specified logger.

type NoOpLogger Uses

type NoOpLogger struct{}

NoOpLogger provides a NOOP logger (the default logging behavior).

Code:

logger := &NoOpLogger{}
fmt.Println("IsDebugEnabled:", logger.IsDebugEnabled())
logger.Debug("Debug", "answer", 42)
logger.Info("Info", "answer", 42)
logger.Warn("Warn", "answer", 42)
logger.Error("Error", "answer", 42)

Output:

IsDebugEnabled: false

func (*NoOpLogger) Debug Uses

func (*NoOpLogger) Debug(string, ...interface{})

Debug is a NOOP.

func (*NoOpLogger) Error Uses

func (*NoOpLogger) Error(string, ...interface{})

Error is a NOOP.

func (*NoOpLogger) Info Uses

func (*NoOpLogger) Info(string, ...interface{})

Info is a NOOP.

func (*NoOpLogger) IsDebugEnabled Uses

func (*NoOpLogger) IsDebugEnabled() bool

IsDebugEnabled returns false.

func (*NoOpLogger) Sync Uses

func (*NoOpLogger) Sync() error

Sync is a NOOP.

func (*NoOpLogger) Warn Uses

func (*NoOpLogger) Warn(string, ...interface{})

Warn is a NOOP.

Directories

PathSynopsis
zapPackage zap provides a wrapper for https://go.uber.org/zap that implements the log.LeveledLogger interface and adds convenience features to logging with zap.

Package log is imported by 2 packages. Updated 2018-04-02. Refresh now. Tools for package owners.