log

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2015 License: Apache-2.0 Imports: 4 Imported by: 28

Documentation

Overview

Package log provides functions for logging debug, informational, warning, and error messages to standard output/error. Clients should set the current log level; only messages at that level or higher will actually be logged. Compared to Go's standard log package, this package supports colored output.

Inspired by https://github.com/cloudflare/cfssl/blob/master/log/log.go

Index

Examples

Constants

This section is empty.

Variables

View Source
var UseColor = true

UseColor, if true, enables colorized output.

Functions

func Debug

func Debug(v ...interface{}) error

Debug logs a debug message to stdout.

Example
Debug("some debug message")
Output:

DEBUG: some debug message

func Debugf added in v0.3.0

func Debugf(format string, v ...interface{}) error

Debugf logs a formatted debug message to stdout.

Example
s := "debug"
Debugf("some %s message", s)
Output:

DEBUG: some debug message

func Error

func Error(v ...interface{}) error

Error logs an error message to stderr.

Example
os.Stderr = os.Stdout
Error("some error message")
Output:

ERROR: some error message

func Errorf added in v0.3.0

func Errorf(format string, v ...interface{}) error

Errorf logs a formatted error message to stderr.

Example
os.Stderr = os.Stdout
s := "error"
Errorf("some %s message", s)
Output:

ERROR: some error message

func Info

func Info(v ...interface{}) error

Info logs an informational message to stdout.

Example
Info("some info message")
Output:

INFO: some info message

func Infof added in v0.3.0

func Infof(format string, v ...interface{}) error

Infof logs a formatted informational message to stdout.

Example
s := "info"
Infof("some %s message", s)
Output:

INFO: some info message

func SetLevel added in v0.3.0

func SetLevel(l Level)

SetLevel changes the current log level to l.

Example
defer SetLevel(LevelDebug)
SetLevel(LevelInfo)

Debug("some debug message")
Info("some info message")
Warn("some warning message")
Output:

INFO: some info message
WARNING: some warning message

func Warn

func Warn(v ...interface{}) error

Warn logs a warning message to stdout.

Example
Warn("some warning message")
Output:

WARNING: some warning message

func Warnf added in v0.3.0

func Warnf(format string, v ...interface{}) error

Warnf logs a formatted warning message to stdout.

Example
s := "warning"
Warnf("some %s message", s)
Output:

WARNING: some warning message

Types

type Level

type Level int

The Level type is the type of all log levels.

const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

The different log levels.

Jump to

Keyboard shortcuts

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