log

package module
v0.0.0-...-0c26ca1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2015 License: MIT Imports: 5 Imported by: 0

README

log Build Status

log provides a small set of functions for extended logging. Log messages have different levels (Debug, Info, Warning, Error), are colorized per level and are prepended with an optional timestamp. Only messages greater or equal to the set log level will be logged to standard out/error.

Installation

Standard go get:

$ go get github.com/toashd/log

Usage & Example

For usage and examples see the Godoc.

alt log

Usage is easy enough:


log.Debug("debug message")
log.Info("info message")
log.Warn("warning message")
log.Error("error message")

log.Errorf("%s error message", "formatted")

Color and timestamp are enabled by default but can be easily disabled.

License

MIT

Documentation

Overview

log provides a small set of functions for extended logging. Log messages have different levels (Debug, Info, Warning, Error), are colorized per level and are prepended with an optional timestamp. Only messages greater or equal to the set log level will be logged to std out/error.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DisableColor = false

DisableColor, if true, disables colorized output.

View Source
var DisableTime = false

DisableTime, if true, disables prepended timestamp.

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

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

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

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

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

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

Level holds the current log level.

const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

Jump to

Keyboard shortcuts

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