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

package log

import "github.com/micro/go-platform/log"

Package log is an interface for structured logging.

Index

Package Files

context.go log.go options.go os.go output.go

Variables

var (
    DefaultLevel      Level = InfoLevel
    DefaultOutputName       = "log.json"

    Levels = map[Level]string{
        DebugLevel: "debug",
        InfoLevel:  "info",
        WarnLevel:  "warn",
        ErrorLevel: "error",
        FatalLevel: "fatal",
    }
)

func NewContext Uses

func NewContext(ctx context.Context, c Log) context.Context

type Event Uses

type Event struct {
    Level     Level  `json:"level"`
    Fields    Fields `json:"fields"`
    Timestamp int64  `json:"timestamp"`
    Message   string `json:"message"`
}

Event represents a single log event

func (*Event) MarshalJSON Uses

func (e *Event) MarshalJSON() ([]byte, error)

type Fields Uses

type Fields map[string]string

type Level Uses

type Level int32
const (
    DebugLevel Level = 0
    InfoLevel  Level = 1
    WarnLevel  Level = 2
    ErrorLevel Level = 3
    FatalLevel Level = 4
)

type Log Uses

type Log interface {
    Init(opts ...Option) error
    Options() Options
    Logger
    String() string
}

A structure log interface which can output to multiple backends.

func FromContext Uses

func FromContext(ctx context.Context) (Log, bool)

func NewLog Uses

func NewLog(opts ...Option) Log

type Logger Uses

type Logger interface {
    // Logger interface
    Debug(args ...interface{})
    Info(args ...interface{})
    Error(args ...interface{})
    Fatal(args ...interface{})
    // Formatted logger
    Debugf(format string, args ...interface{})
    Infof(format string, args ...interface{})
    Errorf(format string, args ...interface{})
    Fatalf(format string, args ...interface{})
    // Specify your own levels
    Log(l Level, args ...interface{})
    Logf(l Level, format string, args ...interface{})
    // Returns with extra fields
    WithFields(f Fields) Logger
}

type Option Uses

type Option func(o *Options)

func WithFields Uses

func WithFields(f Fields) Option

func WithLevel Uses

func WithLevel(l Level) Option

func WithOutput Uses

func WithOutput(ot Output) Option

type Options Uses

type Options struct {
    // the current log level
    Level Level
    // the output to write to
    Outputs []Output
    // include a set of fields
    Fields Fields

    // Alternative options
    Context context.Context
}

type Output Uses

type Output interface {
    // Send an event
    Send(*Event) error
    // Flush any buffered events
    Flush() error
    // Discard the output
    Close() error
    // Name of output
    String() string
}

An output represents a file, indexer, syslog, etc

func NewOutput Uses

func NewOutput(opts ...OutputOption) Output

type OutputOption Uses

type OutputOption func(o *OutputOptions)

func OutputName Uses

func OutputName(name string) OutputOption

type OutputOptions Uses

type OutputOptions struct {
    // filepath, url, etc
    Name string
}

Directories

PathSynopsis
protoPackage go_micro_os_log is a generated protocol buffer package.

Package log imports 5 packages (graph) and is imported by 2 packages. Updated 2018-02-20. Refresh now. Tools for package owners.