log: github.com/go-playground/log Index | Files | Directories

package log

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

Index

Package Files

byte_pool.go default_logger.go entry.go errors.go level.go log.go

Constants

const (
    // DefaultTimeFormat is the default time format when parsing Time values.
    // it is exposed to allow handlers to use and not have to redefine
    DefaultTimeFormat = "2006-01-02T15:04:05.000000000Z07:00"
)

Variables

var AllLevels = []Level{
    DebugLevel,
    InfoLevel,
    NoticeLevel,
    WarnLevel,
    ErrorLevel,
    PanicLevel,
    AlertLevel,
    FatalLevel,
}

AllLevels is an array of all log levels, for easier registering of all levels to a handler

func AddHandler Uses

func AddHandler(h Handler, levels ...Level)

AddHandler adds a new log handler and accepts which log levels that handler will be triggered for

func Alert Uses

func Alert(v ...interface{})

Alert logs an alert log entry

func Alertf Uses

func Alertf(s string, v ...interface{})

Alertf logs an alert log entry with formatting

func Debug Uses

func Debug(v ...interface{})

Debug logs a debug entry

func Debugf Uses

func Debugf(s string, v ...interface{})

Debugf logs a debug entry with formatting

func Error Uses

func Error(v ...interface{})

Error logs an error log entry

func Errorf Uses

func Errorf(s string, v ...interface{})

Errorf logs an error log entry with formatting

func Fatal Uses

func Fatal(v ...interface{})

Fatal logs a fatal log entry

func Fatalf Uses

func Fatalf(s string, v ...interface{})

Fatalf logs a fatal log entry with formatting

func HandleEntry Uses

func HandleEntry(e Entry)

HandleEntry handles the log entry and fans out to all handlers with the proper log level This is exposed to allow for centralized logging whereby the log entry is marshalled, passed to a central logging server, unmarshalled and finally fanned out from there.

func Info Uses

func Info(v ...interface{})

Info logs a normal. information, entry

func Infof Uses

func Infof(s string, v ...interface{})

Infof logs a normal. information, entry with formatiing

func Notice Uses

func Notice(v ...interface{})

Notice logs a notice log entry

func Noticef Uses

func Noticef(s string, v ...interface{})

Noticef logs a notice log entry with formatting

func Panic Uses

func Panic(v ...interface{})

Panic logs a panic log entry

func Panicf Uses

func Panicf(s string, v ...interface{})

Panicf logs a panic log entry with formatting

func RemoveHandler Uses

func RemoveHandler(h Handler)

RemoveHandler removes an existing handler

func RemoveHandlerLevels Uses

func RemoveHandlerLevels(h Handler, levels ...Level)

RemoveHandlerLevels removes the supplied levels, if no more levels exists for the handler it will no longer be registered and need to to added via AddHandler again.

func SetContext Uses

func SetContext(ctx context.Context, e Entry) context.Context

SetContext sets a log entry into the provided context

func SetExitFunc Uses

func SetExitFunc(fn func(code int))

SetExitFunc sets the provided function as the exit function used in Fatal(), Fatalf(), Panic() and Panicf(). This is primarily used when wrapping this library, you can set this to to enable testing (with coverage) of your Fatal() and Fatalf() methods.

func SetWithErrorFn Uses

func SetWithErrorFn(fn func(Entry, error) Entry)

SetWithErrorFn sets a custom WithError function handlers

func Warn Uses

func Warn(v ...interface{})

Warn logs a warn log entry

func Warnf Uses

func Warnf(s string, v ...interface{})

Warnf logs a warn log entry with formatting

func WithDefaultFields Uses

func WithDefaultFields(fields ...Field)

WithDefaultFields adds fields to the underlying logger instance

type ByteArrayPool Uses

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

BytePool represents a reusable byte pool. It is a centralized global instance for this package and can be accessed by calling log.BytePool(). It is intended to be used by Handlers.

func BytePool Uses

func BytePool() *ByteArrayPool

BytePool returns a sync.Pool of bytes that multiple handlers can use in order to reduce allocation and keep a central copy for reuse.

func (*ByteArrayPool) Get Uses

func (p *ByteArrayPool) Get() []byte

func (*ByteArrayPool) Put Uses

func (p *ByteArrayPool) Put(b []byte)

type Entry Uses

type Entry struct {
    Message   string    `json:"message"`
    Timestamp time.Time `json:"timestamp"`
    Fields    []Field   `json:"fields"`
    Level     Level     `json:"level"`
    // contains filtered or unexported fields
}

Entry defines a single log entry

func GetContext Uses

func GetContext(ctx context.Context) Entry

GetContext returns the log Entry found in the context, or a new Default log Entry if none is found

func WithError Uses

func WithError(err error) Entry

WithError add a minimal stack trace to the log Entry

func WithField Uses

func WithField(key string, value interface{}) Entry

WithField returns a new log entry with the supplied field.

func WithFields Uses

func WithFields(fields ...Field) Entry

WithFields returns a new log entry with the supplied fields appended

func WithTrace Uses

func WithTrace() Entry

WithTrace withh add duration of how long the between this function call and the susequent log

func (Entry) Alert Uses

func (e Entry) Alert(v ...interface{})

Alert logs an alert log entry

func (Entry) Alertf Uses

func (e Entry) Alertf(s string, v ...interface{})

Alertf logs an alert log entry with formatting

func (Entry) Debug Uses

func (e Entry) Debug(v ...interface{})

Debug logs a debug entry

func (Entry) Debugf Uses

func (e Entry) Debugf(s string, v ...interface{})

Debugf logs a debug entry with formatting

func (Entry) Error Uses

func (e Entry) Error(v ...interface{})

Error logs an error log entry

func (Entry) Errorf Uses

func (e Entry) Errorf(s string, v ...interface{})

Errorf logs an error log entry with formatting

func (Entry) Fatal Uses

func (e Entry) Fatal(v ...interface{})

Fatal logs a fatal log entry

func (Entry) Fatalf Uses

func (e Entry) Fatalf(s string, v ...interface{})

Fatalf logs a fatal log entry with formatting

func (Entry) Info Uses

func (e Entry) Info(v ...interface{})

Info logs a normal. information, entry

func (Entry) Infof Uses

func (e Entry) Infof(s string, v ...interface{})

Infof logs a normal. information, entry with formatting

func (Entry) Notice Uses

func (e Entry) Notice(v ...interface{})

Notice logs a notice log entry

func (Entry) Noticef Uses

func (e Entry) Noticef(s string, v ...interface{})

Noticef logs a notice log entry with formatting

func (Entry) Panic Uses

func (e Entry) Panic(v ...interface{})

Panic logs a panic log entry

func (Entry) Panicf Uses

func (e Entry) Panicf(s string, v ...interface{})

Panicf logs a panic log entry with formatting

func (Entry) Warn Uses

func (e Entry) Warn(v ...interface{})

Warn logs a warn log entry

func (Entry) Warnf Uses

func (e Entry) Warnf(s string, v ...interface{})

Warnf logs a warn log entry with formatting

func (Entry) WithError Uses

func (e Entry) WithError(err error) Entry

WithError add a minimal stack trace to the log Entry

func (Entry) WithField Uses

func (e Entry) WithField(key string, value interface{}) Entry

WithField returns a new log entry with the supplied field.

func (Entry) WithFields Uses

func (e Entry) WithFields(fields ...Field) Entry

WithFields returns a new log entry with the supplied fields appended

func (Entry) WithTrace Uses

func (e Entry) WithTrace() Entry

WithTrace with add duration of how long the between this function call and the subsequent log

type Field Uses

type Field struct {
    Key   string      `json:"key"`
    Value interface{} `json:"value"`
}

Field is a single Field key and value

func F Uses

func F(key string, value interface{}) Field

F creates a new Field using the supplied key + value. it is shorthand for defining field manually

type Fields Uses

type Fields []Field

Fields is the type to send to WithFields

type Handler Uses

type Handler interface {
    Log(Entry)
}

Handler is an interface that log handlers need to comply with

type Level Uses

type Level uint8

Level of the log

const (
    DebugLevel Level = iota
    InfoLevel
    NoticeLevel
    WarnLevel
    ErrorLevel
    PanicLevel
    AlertLevel
    FatalLevel // same as syslog CRITICAL
)

Log levels.

func (Level) MarshalJSON Uses

func (l Level) MarshalJSON() ([]byte, error)

MarshalJSON implementation.

func (Level) String Uses

func (l Level) String() string

func (*Level) UnmarshalJSON Uses

func (l *Level) UnmarshalJSON(b []byte) error

UnmarshalJSON implementation.

Directories

PathSynopsis
handlers/consolePackage console allows for log messages to be sent to a any writer, default os.Stderr.
handlers/emailPackage email allows for log messages to be sent via email.
handlers/httpPackage http allows for log messages to be sent via http.
handlers/http/hipchatPackage hipchat allows for log messages to be sent to a hipchat room.
handlers/jsonPackage json implements a JSON handler.
handlers/syslogPackage syslog allows for log messages to be sent via syslog.

Package log imports 15 packages (graph) and is imported by 79 packages. Updated 2019-05-13. Refresh now. Tools for package owners.