log

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2015 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Level   Level     // log level.
	Time    time.Time // time of the log event.
	Message string    // log message (optional).
	Fields  Fields    // extra fields of the log entry (optional).
}

Entry represents a log entry.

type Fields

type Fields map[string]interface{}

Fields represents the key-value pairs in a log Entry.

func (Fields) Get

func (f Fields) Get(key string) interface{}

Get returns a value associated with the given key.

func (Fields) OrderedKeys

func (f Fields) OrderedKeys() (keys []string)

OrderedKeys returns the keys of f that sorted in increasing order. This is used if you need the consistent map iteration order. See also http://golang.org/doc/go1.3#map

type Formatter

type Formatter interface {
	// Format formats a log entry.
	// Format writes formatted entry to the w.
	Format(w io.Writer, entry *Entry) error
}

Formatter is an interface that formatter for a log entry.

type LTSVFormatter

type LTSVFormatter struct {
}

LTSVFormatter is the formatter of Labeled Tab-separated Values. See http://ltsv.org/ for more details.

func (*LTSVFormatter) Format

func (f *LTSVFormatter) Format(w io.Writer, entry *Entry) error

Format formats an entry to Labeled Tab-separated Values format.

type Level

type Level uint32

Level represents a log level.

const (
	NONE Level = iota
	DEBUG
	INFO
	WARN
	ERROR
	FATAL
	PANIC
)

The log levels.

func (Level) String

func (i Level) String() string

type Logger

type Logger interface {
	// Debug calls Logger.Output to print to the logger with DEBUG level.
	// Arguments are handled in the manner of fmt.Print.
	// If the current log level is upper than DEBUG, it won't be the output.
	Debug(v ...interface{})

	// Debugf calls Logger.Output to print to the logger with DEBUG level.
	// Arguments are handled in the manner of fmt.Printf.
	// If the current log level is upper than DEBUG, it won't be the output.
	Debugf(format string, v ...interface{})

	// Debugln calls Logger.Output to print to the logger with DEBUG level.
	// Arguments are handled in the manner of fmt.Println.
	// If the current log level is upper than DEBUG, it won't be the output.
	Debugln(v ...interface{})

	// Info calls Logger.Output to print to the logger with INFO level.
	// Arguments are handled in the manner of fmt.Print.
	// If the current log level is upper than INFO, it won't be the output.
	Info(v ...interface{})

	// Infof calls Logger.Output to print to the logger with INFO level.
	// Arguments are handled in the manner of fmt.Printf.
	// If the current log level is upper than INFO, it won't be the output.
	Infof(format string, v ...interface{})

	// Infoln calls Logger.Output to print to the logger with INFO level.
	// Arguments are handled in the manner of fmt.Println.
	// If the current log level is upper than INFO, it won't be the output.
	Infoln(v ...interface{})

	// Warn calls Logger.Output to print to the logger with WARN level.
	// Arguments are handled in the manner of fmt.Print.
	// If the current log level is upper than WARN, it won't be the output.
	Warn(v ...interface{})

	// Warnf calls Logger.Output to print to the logger with WARN level.
	// Arguments are handled in the manner of fmt.Printf.
	// If the current log level is upper than WARN, it won't be the output.
	Warnf(format string, v ...interface{})

	// Warnln calls Logger.Output to print to the logger with WARN level.
	// Arguments are handled in the manner of fmt.Println.
	// If the current log level is upper than WARN, it won't be the output.
	Warnln(v ...interface{})

	// Error calls Logger.Output to print to the logger with ERROR level.
	// Arguments are handled in the manner of fmt.Print.
	// If the current log level is upper than ERROR, it won't be the output.
	Error(v ...interface{})

	// Errorf calls Logger.Output to print to the logger with ERROR level.
	// Arguments are handled in the manner of fmt.Printf.
	// If the current log level is upper than ERROR, it won't be the output.
	Errorf(format string, v ...interface{})

	// Errorln calls Logger.Output to print to the logger with ERROR level.
	// Arguments are handled in the manner of fmt.Println.
	// If the current log level is upper than ERROR, it won't be the output.
	Errorln(v ...interface{})

	// Fatal calls Logger.Output to print to the logger with FATAL level.
	// Arguments are handled in the manner of fmt.Print.
	// Also calls os.Exit(1) after the output.
	Fatal(v ...interface{})

	// Fatalf calls Logger.Output to print to the logger with FATAL level.
	// Arguments are handled in the manner of fmt.Printf.
	// Also calls os.Exit(1) after the output.
	Fatalf(format string, v ...interface{})

	// Fatalln calls Logger.Output to print to the logger with FATAL level.
	// Arguments are handled in the manner of fmt.Println.
	// Also calls os.Exit(1) after the output.
	Fatalln(v ...interface{})

	// Panic calls Logger.Output to print to the logger with PANIC level.
	// Arguments are handled in the manner of fmt.Print.
	// Also calls panic() after the output.
	Panic(v ...interface{})

	// Panicf calls Logger.Output to print to the logger with PANIC level.
	// Arguments are handled in the manner of fmt.Printf.
	// Also calls panic() after the output.
	Panicf(format string, v ...interface{})

	// Panicln calls Logger.Output to print to the logger with PANIC level.
	// Arguments are handled in the manner of fmt.Println.
	// Also calls panic() after the output.
	Panicln(v ...interface{})

	// Print calls Logger.Output to print to the logger with NONE level.
	// Arguments are handled in the manner of fmt.Print.
	Print(v ...interface{})

	// Printf calls Logger.Output to print to the logger with NONE level.
	// Arguments are handled in the manner of fmt.Printf.
	Printf(format string, v ...interface{})

	// Println calls Logger.Output to print to the logger with NONE level.
	// Arguments are handled in the manner of fmt.Println.
	Println(v ...interface{})

	// Output writes the output for a logging event with the given level.
	// The given message will be format by Formatter. Also a newline is appended
	// to the message before the output.
	Output(level Level, message string)

	// With returns a new Logger with fields.
	With(fields Fields) Logger

	// Level returns the current log level.
	Level() Level

	// SetLevel sets the log level.
	SetLevel(level Level)
}

Logger is the interface that logger.

func New

func New(out io.Writer, formatter Formatter, level Level) Logger

New creates a new Logger.

type RawFormatter added in v0.7.0

type RawFormatter struct{}

RawFormatter is a formatter that doesn't format. RawFormatter doesn't output the almost fields of the entry except the Message.

func (*RawFormatter) Format added in v0.7.0

func (f *RawFormatter) Format(w io.Writer, entry *Entry) error

Format outputs entry.Message.

Jump to

Keyboard shortcuts

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