go-log: github.com/segmentio/go-log Index | Files

package log

import "github.com/segmentio/go-log"

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

Package Files

log.go std.go

Variables

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

func Alert Uses

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

Alert log.

func Check Uses

func Check(err error)

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

func Critical Uses

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

Critical log.

func Debug Uses

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

Debug log.

func Emergency Uses

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

Emergency log.

func Error Uses

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

Error log.

func Fatalf Uses

func Fatalf(msg string, args ...interface{})

Fatalf is equivalent to Error() followed by a call to os.Exit(1).

func Info Uses

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

Info log.

func Notice Uses

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

Notice log.

func SetLevel Uses

func SetLevel(level Level)

SetLevel wrapper.

func SetLevelString Uses

func SetLevelString(level string)

SetLevelString wrapper.

func SetPrefix Uses

func SetPrefix(str string)

SetPrefix wrapper.

func Warning Uses

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

Warning log.

type Level Uses

type Level int

Level.

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

Levels.

type Logger Uses

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

Logger.

func New Uses

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 Uses

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

Alert log.

func (*Logger) Check Uses

func (l *Logger) Check(err error)

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

func (*Logger) Critical Uses

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

Critical log.

func (*Logger) Debug Uses

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

Debug log.

func (*Logger) Emergency Uses

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

Emergency log.

func (*Logger) Error Uses

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

Error log.

func (*Logger) Fatalf Uses

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

Fatalf is equivalent to Error() followed by a call to os.Exit(1).

func (*Logger) Info Uses

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

Info log.

func (*Logger) Log Uses

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

Log a message.

func (*Logger) New Uses

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

New logger which inherits the writer and level.

func (*Logger) Notice Uses

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

Notice log.

func (*Logger) SetLevel Uses

func (l *Logger) SetLevel(level Level)

SetLevel changes the log `level`.

func (*Logger) SetLevelFromEnv Uses

func (l *Logger) SetLevelFromEnv(name string)

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

func (*Logger) SetLevelString Uses

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 Uses

func (l *Logger) SetPrefix(str string)

SetPrefix changes the prefix to `str`.

func (*Logger) Warning Uses

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

Warning log.

func (*Logger) Write Uses

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

Write to the logger.

Package log imports 6 packages (graph) and is imported by 25 packages. Updated 2016-07-31. Refresh now. Tools for package owners.