wlog

package
v0.1.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2015 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Provides an io.Writer that filters log messages based on a log level.

Valid log levels are: DEBUG, INFO, WARN, ERROR.

Log messages need to begin with a L! where L is one of D, I, W, or E.

Examples:

log.Println("D! this is a debug log")
log.Println("I! this is an info log")
log.Println("W! this is a warn log")
log.Println("E! this is an error log")

Simply pass a instance of wlog.Writer to log.New or use the helper wlog.New function.

The log level can be changed via the SetLevel or the SetLevelFromName functions.

Index

Constants

View Source
const Delimeter = '!'

Variables

View Source
var Levels = map[byte]Level{
	'D': DEBUG,
	'I': INFO,
	'W': WARN,
	'E': ERROR,
}
View Source
var ReverseLevels map[Level]byte

Functions

func New

func New(w io.Writer, prefix string, flag int) *log.Logger

func SetLevel

func SetLevel(l Level)

func SetLevelFromName

func SetLevelFromName(level string) error

Set the log level via a string name. To set it directly use 'logLevel'.

Types

type Level

type Level int
const (
	DEBUG Level
	INFO
	WARN
	ERROR
	OFF
)

func LogLevel

func LogLevel() Level

type StaticLevelWriter

type StaticLevelWriter struct {
	// contains filtered or unexported fields
}

func NewStaticLevelWriter

func NewStaticLevelWriter(w io.Writer, level Level) *StaticLevelWriter

func (*StaticLevelWriter) Write

func (w *StaticLevelWriter) Write(buf []byte) (int, error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Implements io.Writer. Checks first byte of write for log level and drops the log if necessary

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) Write

func (w *Writer) Write(buf []byte) (int, error)

Jump to

Keyboard shortcuts

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