cookoo: github.com/Masterminds/cookoo/log Index | Examples | Files

package log

import "github.com/Masterminds/cookoo/log"

Package log contains logging helpers.

EXPERIMENTAL! This may change prior to the final release of this version!

This package provides syslog-style logging messages. See `log/syslog` in Go's documentation. A notable difference, though, is that this also provides formatter variants for all of the log levels.

This uses the Context.Log* functions beneath the hood, so any logger configuration for that will also hold true for this.

Code:

_, _, c := cookoo.Cookoo()

// Set logging to go to Stdout.
c.AddLogger("stdout", os.Stdout)

// Set the log level to any of the Log* constants.
Level = LogInfo

// Functions are named as they are in log/syslog.
Err(c, "Failed to do something.")

// There are also formatting versions of every log function.
Infof(c, "Informational message with %s.", "formatting")

// Shorthand for if Level >= LogDebug
if Debugging() {
    Debug(c, "This is a debug message.")
}

// You can test for any level.
if Level >= LogWarning {
    Warn(c, "And this is a warning.")
}

Stack(c, "Stack trace from here.")

Index

Examples

Package Files

log.go

Constants

const (
    LabelEmerg   = "[emergency] "
    LabelAlert   = "[alert] "
    LabelCrit    = "[critical] "
    LabelErr     = "[error] "
    LabelWarning = "[warning] "
    LabelNotice  = "[notice] "
    LabelInfo    = "[info] "
    LabelDebug   = "[debug] "
)

Labels for log levels.

Variables

var Label = [8]string{
    LabelEmerg,
    LabelAlert,
    LabelCrit,
    LabelErr,
    LabelWarning,
    LabelNotice,
    LabelInfo,
    LabelDebug,
}

func Alert Uses

func Alert(c cookoo.Context, args ...interface{})

Alertf logs an alert.

func Alertf Uses

func Alertf(c cookoo.Context, msg string, args ...interface{})

Alertf logs an alert.

func Crit Uses

func Crit(c cookoo.Context, args ...interface{})

Critf logs a critical message.

func Critf Uses

func Critf(c cookoo.Context, msg string, args ...interface{})

Critf logs a critical message.

func Debug Uses

func Debug(c cookoo.Context, args ...interface{})

Debugf logs a debug message.

func Debugf Uses

func Debugf(c cookoo.Context, msg string, args ...interface{})

Debugf logs a debug message.

func Debugging Uses

func Debugging() bool

Debugging returns true if the level is set to allow debugging.

Whether or not the log message is sent to the underlying logger is determined based on the Level. However, using checks like this can prevent doing costly debug computations just for the sake of logging.

if Debugging() {
	// Do something expensive.
	costlyOperation()

	Debug(c, "msg")
}

Otherwise, this will write the message to the lower-level logger, which can then decide (presumably based on Level) what to do with the message.

func Emerg Uses

func Emerg(c cookoo.Context, args ...interface{})

Emergf logs an emergency.

func Emergf Uses

func Emergf(c cookoo.Context, msg string, args ...interface{})

Emergf logs an emergency.

func Err Uses

func Err(c cookoo.Context, args ...interface{})

Errf logs an error message.

func Errf Uses

func Errf(c cookoo.Context, msg string, args ...interface{})

Errf logs an error message.

func Info Uses

func Info(c cookoo.Context, args ...interface{})

Infof logs an informational message.

func Infof Uses

func Infof(c cookoo.Context, msg string, args ...interface{})

Infof logs an informational message.

func Notice Uses

func Notice(c cookoo.Context, args ...interface{})

Noticef logs a notice.

func Noticef Uses

func Noticef(c cookoo.Context, msg string, args ...interface{})

Noticef logs a notice.

func Stack Uses

func Stack(c cookoo.Context, msg string)

Stack dumps a stack trace to the log. It uses the LogDebug level.

This limits the size of the returned stack to 4096 bytes.

func Warn Uses

func Warn(c cookoo.Context, args ...interface{})

Warnf logs a warning.

func Warnf Uses

func Warnf(c cookoo.Context, msg string, args ...interface{})

Warnf logs a warning.

type LogLevel Uses

type LogLevel uint8

LogLevel describes the log levels.

const (
    LogEmerg LogLevel = iota
    LogAlert
    LogCrit
    LogErr
    LogWarning
    LogNotice
    LogInfo
    LogDebug
)

Log levels correspond to UNIX/syslog logging levels.

var Level LogLevel = LogDebug

Package log imports 2 packages (graph) and is imported by 167 packages. Updated 2016-07-17. Refresh now. Tools for package owners.