log

package
v0.0.0-...-2efaa0c Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: Apache-2.0 Imports: 5 Imported by: 23 modules, 27 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Log GoDoc

Provides a high level abstraction for structured logging.

Interface

This is an interface for structured logging. It provides a simple way of creating logs messages with metadata with the ability to send to multiple outputs.

// A structure log interface which can
// output to multiple backends.
type Log interface {
	Init(opts ...Option) error
	Options() Options
	Logger
	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
}

func NewLog(opts ...Option) Log {
	return newOS(opts...)
}

Supported Backends

  • File

Documentation

Overview

Package log is an interface for structured logging.

Index

Constants

This section is empty.

Variables

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

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

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

func (*Event) MarshalJSON

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

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
)

type Log

type Log interface {
	Init(opts ...Option) error
	Options() Options
	Logger
	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
output
Package go_micro_os_log is a generated protocol buffer package.
Package go_micro_os_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