gournal: github.com/akutz/gournal Index | Files | Directories

package gournal

import "github.com/akutz/gournal"

Package gournal (pronounced "Journal") is a Context-aware logging framework.

Gournal introduces the Google Context type (https://blog.golang.org/context) as a first-class parameter to all common log functions such as Info, Debug, etc.

Instead of being Yet Another Go Log library, Gournal actually takes its inspiration from the Simple Logging Facade for Java (SLF4J). Gournal is not attempting to replace anyone's favorite logger, rather existing logging frameworks such as Logrus, Zap, etc. can easily participate as a Gournal Appender.

For more information on Gournal's features or how to use it, please refer to the project's README file or https://github.com/akutz/gournal.

Index

Package Files

gournal.go gournal_iowriter.go

Variables

var (
    // ErrorKey defines the key when adding errors using WithError.
    ErrorKey = "error"

    // DefaultLevel is used when a Level is not present in a Context.
    DefaultLevel = ErrorLevel

    // DefaultAppender is used when an Appender is not present in a Context.
    DefaultAppender = NewAppender()

    // DefaultContext is used when a log method is invoked with a nil Context.
    DefaultContext = context.Background()
)

func AppenderKey Uses

func AppenderKey() interface{}

AppenderKey returns the Context key for storing and retrieving an Appender object.

func Debug Uses

func Debug(ctx context.Context, msg string, args ...interface{})

Debug emits a log entry at the DEBUG level.

func Error Uses

func Error(ctx context.Context, msg string, args ...interface{})

Error emits a log entry at the ERROR level.

func Fatal Uses

func Fatal(ctx context.Context, msg string, args ...interface{})

Fatal emits a log entry at the FATAL level.

func FieldsKey Uses

func FieldsKey() interface{}

FieldsKey returns the Context key for storing and retrieving Context-specific data that is appended along with each log entry. Three different types of data are inspected for this context key:

* map[string]interface{}

* func() map[string]interface{}

* func(ctx context.Context,
       lvl Level,
       fields map[string]interface{},
       msg string) map[string]interface{}

func Info Uses

func Info(ctx context.Context, msg string, args ...interface{})

Info emits a log entry at the INFO level.

func LevelKey Uses

func LevelKey() interface{}

LevelKey returns the Context key used for storing and retrieving the log level.

func Panic Uses

func Panic(ctx context.Context, msg string, args ...interface{})

Panic emits a log entry at the PANIC level.

func Print Uses

func Print(ctx context.Context, msg string, args ...interface{})

Print emits a log entry at the INFO level.

func Warn Uses

func Warn(ctx context.Context, msg string, args ...interface{})

Warn emits a log entry at the WARN level.

type Appender Uses

type Appender interface {

    // Append is implemented by logging frameworks to accept the log entry
    // at the provided level, its message, and its associated field data.
    Append(
        ctx context.Context,
        lvl Level,
        fields map[string]interface{},
        msg string)
}

Appender is the interface that must be implemented by the logging frameworks which are members of the Gournal facade.

func NewAppender Uses

func NewAppender() Appender

NewAppender returns an Appender that writes to os.Stdout.

func NewAppenderWithOptions Uses

func NewAppenderWithOptions(w io.Writer) Appender

NewAppenderWithOptions returns an Appender that writes to the provided io.Writer object.

type Entry Uses

type Entry interface {

    // WithField adds a single field to the Entry. The provided key will
    // override an existing, equivalent key in the Entry.
    WithField(key string, value interface{}) Entry

    // WithFields adds a map to the Entry. Keys in the provided map will
    // override existing, equivalent keys in the Entry.
    WithFields(fields map[string]interface{}) Entry

    // WithError adds the provided error to the Entry using the ErrorKey value
    // as the key.
    WithError(err error) Entry

    // Debug emits a log entry at the DEBUG level.
    Debug(ctx context.Context, msg string, args ...interface{})

    // Info emits a log entry at the INFO level.
    Info(ctx context.Context, msg string, args ...interface{})

    // Print emits a log entry at the INFO level.
    Print(ctx context.Context, msg string, args ...interface{})

    // Warn emits a log entry at the WARN level.
    Warn(ctx context.Context, msg string, args ...interface{})

    // Error emits a log entry at the ERROR level.
    Error(ctx context.Context, msg string, args ...interface{})

    // Fatal emits a log entry at the FATAL level.
    Fatal(ctx context.Context, msg string, args ...interface{})

    // Panic emits a log entry at the PANIC level.
    Panic(ctx context.Context, msg string, args ...interface{})
}

Entry is the interface for types that contain information to be emmitted to a log appender.

func WithError Uses

func WithError(err error) Entry

WithError adds the provided error to the Entry using the ErrorKey value as the key.

func WithField Uses

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

WithField adds a single field to the Entry. The provided key will override an existing, equivalent key in the Entry.

func WithFields Uses

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

WithFields adds a map to the Entry. Keys in the provided map will override existing, equivalent keys in the Entry.

type Level Uses

type Level uint8

Level is a log level.

const (
    // UnknownLevel is an unknown level.
    UnknownLevel Level = iota

    // PanicLevel level, highest level of severity. Logs and then calls panic
    // with the message passed to Debug, Info, ...
    PanicLevel

    // FatalLevel level. Logs and then calls os.Exit(1). It will exit even
    // if the logging level is set to Panic.
    FatalLevel

    // ErrorLevel level. Logs. Used for errors that should definitely be noted.
    // Commonly used for hooks to send errors to an error tracking service.
    ErrorLevel

    // WarnLevel level. Non-critical entries that deserve eyes.
    WarnLevel

    // InfoLevel level. General operational entries about what's going on
    // inside the application.
    InfoLevel

    // DebugLevel level. Usually only enabled when debugging. Very verbose
    // logging.
    DebugLevel
)

These are the different logging levels.

func ParseLevel Uses

func ParseLevel(lvl string) Level

ParseLevel parses a string and returns its constant.

func (Level) String Uses

func (level Level) String() string

String returns string representation of a Level.

type Logger Uses

type Logger interface {

    // Debug emits a log entry at the DEBUG level.
    Debug(msg string, args ...interface{})

    // Info emits a log entry at the INFO level.
    Info(msg string, args ...interface{})

    // Print emits a log entry at the INFO level.
    Print(msg string, args ...interface{})

    // Warn emits a log entry at the WARN level.
    Warn(msg string, args ...interface{})

    // Error emits a log entry at the ERROR level.
    Error(msg string, args ...interface{})

    // Fatal emits a log entry at the FATAL level.
    Fatal(msg string, args ...interface{})

    // Panic emits a log entry at the PANIC level.
    Panic(msg string, args ...interface{})
}

Logger provides backwards-compatibility for code that does not yet use context-aware logging.

func New Uses

func New(ctx context.Context) Logger

New returns a Logger for the provided context.

Directories

PathSynopsis
logrusPackage logrus provides a Logrus logger that implements the Gournal Appender interface.
stdlibPackage stdlib provides a StdLib logger that implements the Gournal Appender interface.
zapPackage zap provides a Zap logger that implements the Gournal Appender interface.

Package gournal imports 7 packages (graph) and is imported by 33 packages. Updated 2018-04-09. Refresh now. Tools for package owners.