log

package
v0.0.1-tiedot Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2014 License: GPL-3.0 Imports: 6 Imported by: 6

README

go-log

Simple printf-style logger which is more or less the same as Go's core logger with log levels.

View the docs.

Example

log.Debug("something")
log.Emergency("hello %s %s", "tobi", "ferret")

l := log.New(os.Stderr, log.DEBUG, "")
l.Debug("something happened")
l.Info("hello %s", "Tobi")
l.Error("boom something exploded")

License

MIT

Documentation

Overview

Simple logger similar to Go's standard logger with log level.

l := log.New(os.Stderr, INFO, "myapp")
l.Error("something exploded")

Default logger:

log.Info("something %s", "here")

Index

Constants

This section is empty.

Variables

View Source
var Log = New(os.Stderr, INFO, "")

Functions

func Alert

func Alert(msg string, args ...interface{}) error

Alert log.

func Check

func Check(err error)

Check if there's an `err` and exit, useful for bootstrapping.

func Critical

func Critical(msg string, args ...interface{}) error

Critical log.

func Debug

func Debug(msg string, args ...interface{}) error

Debug log.

func Emergency

func Emergency(msg string, args ...interface{}) error

Emergency log.

func Error

func Error(msg string, args ...interface{}) error

Error log.

func Info

func Info(msg string, args ...interface{}) error

Info log.

func Notice

func Notice(msg string, args ...interface{}) error

Notice log.

func SetLevel

func SetLevel(level Level)

SetLevel wrapper.

func SetLevelString

func SetLevelString(level string)

SetLevelString wrapper.

func SetPrefix

func SetPrefix(str string)

SetPrefix wrapper.

func Warning

func Warning(msg string, args ...interface{}) error

Warning log.

Types

type Level

type Level int

Level.

const (
	DEBUG Level = iota
	INFO
	NOTICE
	WARNING
	ERROR
	CRITICAL
	ALERT
	EMERGENCY
)

Levels.

type Logger

type Logger struct {
	Writer io.Writer
	Level  Level
	Prefix string
	sync.Mutex
}

Logger.

func New

func New(w io.Writer, level Level, prefix string) *Logger

New logger which writes to `w` at the given `level`. Optionally provide a `prefix` for the logger.

func (*Logger) Alert

func (l *Logger) Alert(msg string, args ...interface{}) error

Alert log.

func (*Logger) Check

func (l *Logger) Check(err error)

Check if there's an `err` and exit, useful for bootstrapping.

func (*Logger) Critical

func (l *Logger) Critical(msg string, args ...interface{}) error

Critical log.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...interface{}) error

Debug log.

func (*Logger) Emergency

func (l *Logger) Emergency(msg string, args ...interface{}) error

Emergency log.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...interface{}) error

Error log.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...interface{}) error

Info log.

func (*Logger) Log

func (l *Logger) Log(lvl string, level Level, msg string, args ...interface{}) error

Log a message.

func (*Logger) New

func (l *Logger) New(prefix string) *Logger

New logger which inherits the writer and level.

func (*Logger) Notice

func (l *Logger) Notice(msg string, args ...interface{}) error

Notice log.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel changes the log `level`.

func (*Logger) SetLevelFromEnv

func (l *Logger) SetLevelFromEnv(name string)

SetLevelFromEnv forces the log level based on the given environment variable `name` when present.

func (*Logger) SetLevelString

func (l *Logger) SetLevelString(level string) error

SetLevelString changes the log `level` via string. This is especially useful for providing a command-line flag to your program to adjust the level.

If the level string is invalid an error is returned.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(str string)

SetPrefix changes the prefix to `str`.

func (*Logger) Warning

func (l *Logger) Warning(msg string, args ...interface{}) error

Warning log.

func (*Logger) Write

func (l *Logger) Write(b []byte) (n int, err error)

Write to the logger.

Jump to

Keyboard shortcuts

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