log

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2015 License: MIT Imports: 2 Imported by: 170

Documentation

Overview

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.

Example
_, _, 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.")
Output:

Index

Examples

Constants

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

Labels for log levels.

Variables

Functions

func Alert

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

Alertf logs an alert.

func Alertf

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

Alertf logs an alert.

func Crit

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

Critf logs a critical message.

func Critf

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

Critf logs a critical message.

func Debug

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

Debugf logs a debug message.

func Debugf

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

Debugf logs a debug message.

func Debugging

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

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

Emergf logs an emergency.

func Emergf

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

Emergf logs an emergency.

func Err

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

Errf logs an error message.

func Errf

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

Errf logs an error message.

func Info

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

Infof logs an informational message.

func Infof

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

Infof logs an informational message.

func Notice

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

Noticef logs a notice.

func Noticef

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

Noticef logs a notice.

func Stack

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

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

Warnf logs a warning.

func Warnf

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

Warnf logs a warning.

Types

type LogLevel

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL