log

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package log provides support for logging to stdout, stderr and file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, v ...interface{})

Debug logs a message with severity DEBUG.

func Debugf

func Debugf(ctx context.Context, format string, v ...interface{})

Debugf logs a message with severity DEBUG in format.

func Error

func Error(ctx context.Context, v ...interface{})

Error logs a message with severity ERROR.

func Errorf

func Errorf(ctx context.Context, format string, v ...interface{})

Errorf logs a message with severity ERROR in format.

func Fatal

func Fatal(ctx context.Context, v ...interface{})

Fatal logs a message with severity FATAL followed by a call to os.Exit(1).

func Fatalf

func Fatalf(ctx context.Context, format string, v ...interface{})

Fatalf logs a message with severity FATAL in format followed by a call to os.Exit(1).

func Info

func Info(ctx context.Context, v ...interface{})

Info logs a message with severity INFO.

func Infof

func Infof(ctx context.Context, format string, v ...interface{})

Infof logs a message with severity INFO in format.

func Panic

func Panic(ctx context.Context, v ...interface{})

Panic logs a message with severity PANIC followed by a call to panic().

func Panicf

func Panicf(ctx context.Context, format string, v ...interface{})

Panicf logs a message with severity PANIC in format followed by a call to panic().

func SetGlobalLogger

func SetGlobalLogger(l *Logger)

SetGlobalLogger sets a logger as global logger.

func Warn

func Warn(ctx context.Context, v ...interface{})

Warn logs a message with severity WARN.

func Warnf

func Warnf(ctx context.Context, format string, v ...interface{})

Warnf logs a message with severity WARN in format.

Types

type Event

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

Event represents a log event. It is instanced by one of the with method of logger and finalized by the log method such as Debug().

func DebugEvent

func DebugEvent(ctx context.Context) *Event

DebugEvent returns a log event with severity DEBUG.

func ErrorEvent

func ErrorEvent(ctx context.Context) *Event

ErrorEvent returns a log event with severity ERROR.

func FatalEvent

func FatalEvent(ctx context.Context) *Event

FatalEvent returns a log event with severity FATAL.

func InfoEvent

func InfoEvent(ctx context.Context) *Event

InfoEvent returns a log event with severity INFO.

func PanicEvent

func PanicEvent(ctx context.Context) *Event

PanicEvent returns a log event with severity PANIC.

func WarnEvent

func WarnEvent(ctx context.Context) *Event

WarnEvent returns a log event with severity WARN.

func (*Event) Bool

func (e *Event) Bool(key string, value bool) *Event

Bool appends string key and bool value to event.

func (*Event) Byte

func (e *Event) Byte(key string, value byte) *Event

Byte appends string key and byte value to event.

func (*Event) Bytes

func (e *Event) Bytes(key string, value []byte) *Event

Bytes appends string key and bytes value to event.

func (*Event) Error

func (e *Event) Error(key string, err error) *Event

Error appends string key and error value to event.

func (*Event) Float32

func (e *Event) Float32(key string, value float32) *Event

Float32 appends string key and float32 value to event.

func (*Event) Float64

func (e *Event) Float64(key string, value float64) *Event

Float64 appends string key and float value to event.

func (*Event) Free

func (e *Event) Free()

Free returns the Event to its EventPool. Callers must not retain references to the Event after calling Free.

func (*Event) Int

func (e *Event) Int(key string, value int) *Event

Int appends string key and int value to event.

func (*Event) Int32

func (e *Event) Int32(key string, value int32) *Event

Int32 appends string key and int32 value to event.

func (*Event) Int64

func (e *Event) Int64(key string, value int64) *Event

Int64 appends string key and int64 value to event.

func (*Event) Interface

func (e *Event) Interface(key string, value interface{}) *Event

Interface appends string key and interface value to event.

func (*Event) Message

func (e *Event) Message(message string)

Message writes the *Event to level writer.

NOTICE: Once this method is called, the *Event should be disposed. Calling twice can have unexpected result.

func (*Event) Messagef

func (e *Event) Messagef(format string, v ...interface{})

Messagef writes the *Event to level writer.

NOTICE: Once this method is called, the *Event should be disposed. Calling twice can have unexpected result.

func (*Event) String

func (e *Event) String(key string, value string) *Event

String appends string key and string value to event.

func (*Event) Time

func (e *Event) Time(key string, value time.Time, format string) *Event

Time appends string key and time value to event.

func (*Event) Uint

func (e *Event) Uint(key string, value uint) *Event

Uint appends string key and uint value to event.

func (*Event) Uint32

func (e *Event) Uint32(key string, value uint32) *Event

Uint32 appends string key and uint32 value to event.

func (*Event) Uint64

func (e *Event) Uint64(key string, value uint64) *Event

Uint64 appends string key and uint64 value to event.

type EventCaller

type EventCaller struct {
	Defined bool
	PC      uintptr
	File    string
	Line    int
	// contains filtered or unexported fields
}

EventCaller represents the caller of a logging function.

func (*EventCaller) Free

func (ec *EventCaller) Free()

Free returns the EventCaller to its EventCallerPool. Callers must not retain references to the EventCaller after calling Free.

func (EventCaller) FullPath

func (ec EventCaller) FullPath() string

FullPath returns a /full/path/to/package/file:line description of the caller.

func (EventCaller) String

func (ec EventCaller) String() string

String returns the full path and line number of the caller.

func (EventCaller) TrimmedPath

func (ec EventCaller) TrimmedPath() string

TrimmedPath returns a package/file:line description of the caller, preserving only the leaf directory name and file name.

type EventCallerPool

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

A EventCallerPool is a type-safe wrapper around a sync.BytesBufferPool.

func NewEventCallerPool

func NewEventCallerPool() EventCallerPool

NewEventCallerPool constructs a new BytesBufferPool.

func (EventCallerPool) Get

func (p EventCallerPool) Get() *EventCaller

Get retrieves a EventCaller from the pool, creating one if necessary.

type EventPool

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

A EventPool is a type-safe wrapper around a sync.BytesBufferPool.

func NewEventPool

func NewEventPool() EventPool

NewEventPool constructs a new BytesBufferPool.

func (EventPool) Get

func (p EventPool) Get() *Event

Get retrieves a Event from the pool, creating one if necessary.

type Flusher

type Flusher interface {
	Flush() error
}

Flusher defines a interface with Flush() method.

type Level

type Level uint8

Level defines log levels.

const (
	// MuteLevel disables the logger.
	MuteLevel Level = iota
	// FatalLevel defines fatal log level.
	FatalLevel
	// PanicLevel defines panic log level.
	PanicLevel
	// ErrorLevel defines error log level.
	ErrorLevel
	// WarnLevel defines warn log level.
	WarnLevel
	// InfoLevel defines info log level.
	InfoLevel
	// DebugLevel defines debug log level.
	DebugLevel
)

func ParseLevel

func ParseLevel(level string) (Level, error)

ParseLevel takes a string level and returns the log level constant.

func (Level) String

func (l Level) String() string

String returns name of the level.

type LevelWriter

type LevelWriter interface {
	io.Writer
	WriteLevel(level Level, message []byte) (n int, err error)
}

LevelWriter defines as interface a writer may implement in order to receive level information with payload.

type Logger

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

Logger presents a logger. The only way to initialize a logger is using the convention construct functions like NewLogger().

func GlobalLogger

func GlobalLogger() *Logger

GlobalLogger returns the global logger.

func NewBufferedFileLogger

func NewBufferedFileLogger(filePath string, flushInterval int, level ...string) (*Logger, error)

NewBufferedFileLogger creates a logger that write into file with buffer. The flushSeconds's unit is second.

func NewBufferedFileLoggerWithError

func NewBufferedFileLoggerWithError(filePath, errFilePath string, flushInterval int, level ...string) (*Logger, error)

NewBufferedFileLoggerWithError creates a logger that write into files with buffer. The flushSeconds's unit is second.

func NewBufferedTerminalLogger

func NewBufferedTerminalLogger(level ...string) (*Logger, error)

NewBufferedTerminalLogger creates a buffered logger that write into terminal.

func NewFileLogger

func NewFileLogger(filePath string, level ...string) (*Logger, error)

NewFileLogger creates a logger that write into file.

func NewFileLoggerWithError

func NewFileLoggerWithError(filePath, errFilePath string, level ...string) (*Logger, error)

NewFileLoggerWithError creates a logger that write into files.

func NewLogger

func NewLogger(out io.Writer, level ...string) (*Logger, error)

NewLogger creates a new logger for given out and level, and the level is optional.

func NewLoggerWithError

func NewLoggerWithError(out, errOut io.Writer, level ...string) (l *Logger, err error)

NewLoggerWithError creates a new logger for given out, err out, level, and the err out can be nil, and the level is optional.

func NewTerminalLogger

func NewTerminalLogger(level ...string) (*Logger, error)

NewTerminalLogger creates a logger that write into terminal.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, v ...interface{})

Debug logs a message with severity DEBUG.

func (*Logger) DebugEvent

func (l *Logger) DebugEvent(ctx context.Context) *Event

DebugEvent returns a log event with severity DEBUG.

func (*Logger) Debugf

func (l *Logger) Debugf(ctx context.Context, format string, v ...interface{})

Debugf logs a message with severity DEBUG in format.

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, v ...interface{})

Error logs a message with severity ERROR.

func (*Logger) ErrorEvent

func (l *Logger) ErrorEvent(ctx context.Context) *Event

ErrorEvent returns a log event with severity ERROR.

func (*Logger) Errorf

func (l *Logger) Errorf(ctx context.Context, format string, v ...interface{})

Errorf logs a message with severity ERROR in format.

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, v ...interface{})

Fatal logs a message with severity FATAL followed by a call to os.Exit(1).

func (*Logger) FatalEvent

func (l *Logger) FatalEvent(ctx context.Context) *Event

FatalEvent returns a log event with severity FATAL.

func (*Logger) Fatalf

func (l *Logger) Fatalf(ctx context.Context, format string, v ...interface{})

Fatalf logs a message with severity FATAL in format followed by a call to os.Exit(1).

func (*Logger) Flush

func (l *Logger) Flush()

Flush writes buffered logs.

func (*Logger) GetLevel

func (l *Logger) GetLevel() string

GetLevel get the log level string.

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, v ...interface{})

Info logs a message with severity INFO.

func (*Logger) InfoEvent

func (l *Logger) InfoEvent(ctx context.Context) *Event

InfoEvent returns a log event with severity INFO.

func (*Logger) Infof

func (l *Logger) Infof(ctx context.Context, format string, v ...interface{})

Infof logs a message with severity INFO in format.

func (*Logger) Panic

func (l *Logger) Panic(ctx context.Context, v ...interface{})

Panic logs a message with severity PANIC followed by a call to panic().

func (*Logger) PanicEvent

func (l *Logger) PanicEvent(ctx context.Context) *Event

PanicEvent returns a log event with severity PANIC.

func (*Logger) Panicf

func (l *Logger) Panicf(ctx context.Context, format string, v ...interface{})

Panicf logs a message with severity PANIC in format followed by a call to panic().

func (*Logger) SetCallerFlag

func (l *Logger) SetCallerFlag(isEnabled bool)

SetCallerFlag sets whether to annotating logs with the caller.

func (*Logger) SetInterestContextKeys

func (l *Logger) SetInterestContextKeys(keys []interface{})

SetInterestContextKeys sets the contexts keys that the logger should be interested in. Value of the interested context key will extract and print as newEvent filed.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string) (err error)

SetLevel sets the log level. Valid levels are "debug", "info", "warn", "error", and "fatal".

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, v ...interface{})

Warn logs a message with severity WARN.

func (*Logger) WarnEvent

func (l *Logger) WarnEvent(ctx context.Context) *Event

WarnEvent returns a log event with severity WARN.

func (*Logger) Warnf

func (l *Logger) Warnf(ctx context.Context, format string, v ...interface{})

Warnf logs a message with severity WARN in format.

type StandardWriter

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

StandardWriter implements io.Writer{} and LevelWriter{} interface.

func (*StandardWriter) Flush

func (sw *StandardWriter) Flush() (err error)

Flush implements the Flusher{} interface.

func (*StandardWriter) Write

func (sw *StandardWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer{} interface.

func (*StandardWriter) WriteLevel

func (sw *StandardWriter) WriteLevel(level Level, message []byte) (n int, err error)

WriteLevel implements the LevelWriter{} interface.

Jump to

Keyboard shortcuts

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