log

package
v0.0.0-...-284234c Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

README

Log - Logging interface

Provides a high level abstraction for centralised logging.

Interface

Potentially offload this to logrus

// A structure log interface which can
// output to multiple backends.
type Log interface {
	Init(opts ...Option) error
	Options() Options
	// the logging interface
	Logger
	// We could be flushing logs on an interval basis
	// Or sending specific stats to the log service
	// Or receive events about changing log config
	Start() error
	Stop() error
	// Name
	String() string
}

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
}

// Event represents a single log event
type Event struct {
	Level     Level  `json:"level"`
	Fields    Fields `json:"fields"`
	Timestamp int64  `json:"timestamp"`
	Message   string `json:"message"`
}

// An output represents a file, indexer, syslog, etc
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
}

Supported Log stores

  • ELK
  • Fluentd
  • Syslog
  • ?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

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

Types

type Event

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

type Fields

type Fields map[string]string

type Level

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

	DefaultOutputName = "log.json"
)

type Log

type Log interface {
	Init(opts ...Option) error
	Options() Options
	// the logging interface
	Logger
	// We could be flushing logs on an interval basis
	// Or sending specific stats to the log service
	// Or receive events about changing log config
	Start() error
	Stop() error
	// Name
	String() string
}

A structure log interface which can output to multiple backends.

func FromContext

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

func NewLog

func NewLog(opts ...Option) Log

type Logger

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

type Option func(o *Options)

func WithFields

func WithFields(f Fields) Option

func WithLevel

func WithLevel(l Level) Option

func WithOutput

func WithOutput(ot Output) Option

type Options

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

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

func NewOutput(opts ...OutputOption) Output

type OutputOption

type OutputOption func(o *OutputOptions)

func OutputName

func OutputName(name string) OutputOption

type OutputOptions

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

Directories

Path Synopsis
Package go_micro_platform_log is a generated protocol buffer package.
Package go_micro_platform_log is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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