log

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoSuchLogger = errors.New("Error: No such logger")

ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger

View Source
var LdJSONFormatter = func() {
	logging.SetFormatter(&PoliteJSONFormatter{})
}

LdJSONFormatter Option formats the event log as line-delimited JSON

View Source
var LevelDebug = func() {
	logging.SetLevel(logging.DEBUG, "")
}

LevelDebug Option sets the log level to debug

View Source
var LevelError = func() {
	logging.SetLevel(logging.ERROR, "")
}

LevelError Option sets the log level to error

View Source
var LevelInfo = func() {
	logging.SetLevel(logging.INFO, "")
}

LevelInfo Option sets the log level to info

View Source
var LogFormats = map[string]string{
	"nocolor": "%{time:2006-01-02 15:04:05.000000} %{level} %{module} %{shortfile}: %{message}",
	"color": ansiGray + "%{time:15:04:05.000} %{color}%{level:5.5s} " + ansiBlue +
		"%{module:10.10s}: %{color:reset}%{message} " + ansiGray + "%{shortfile}%{color:reset}",
}
View Source
var TextFormatter = func() {
	logging.SetFormatter(logging.DefaultFormatter)
}

TextFormatter Option formats the event log as human-readable plain-text

View Source
var WriterGroup = new(MirrorWriter)

Global writer group for logs to output to

Functions

func Configure

func Configure(options ...Option)

Configure applies the provided options sequentially from left to right

func ContextWithLoggable

func ContextWithLoggable(ctx context.Context, l Loggable) context.Context

ContextWithLoggable returns a derived context which contains the provided Loggable. Any Events logged with the derived context will include the provided Loggable.

func FormatRFC3339

func FormatRFC3339(t time.Time) string

func SetAllLoggers

func SetAllLoggers(lvl logging.Level)

SetAllLoggers changes the logging.Level of all loggers to lvl

func SetDebugLogging

func SetDebugLogging()

SetDebugLogging calls SetAllLoggers with logging.DEBUG

func SetLogLevel

func SetLogLevel(name, level string) error

SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems

func SetupLogging

func SetupLogging()

SetupLogging will initialize the logger backend and set the flags.

Types

type EventInProgress

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

func (*EventInProgress) Append

func (eip *EventInProgress) Append(l Loggable)

Append adds loggables to be included in the call to Done

func (*EventInProgress) Close

func (eip *EventInProgress) Close() error

Close is an alias for done

func (*EventInProgress) Done

func (eip *EventInProgress) Done()

Done creates a new Event entry that includes the duration and appended loggables.

func (*EventInProgress) SetError

func (eip *EventInProgress) SetError(err error)

SetError includes the provided error

type EventLogger

type EventLogger interface {
	StandardLogger

	// Event merges structured data from the provided inputs into a single
	// machine-readable log event.
	//
	// If the context contains metadata, a copy of this is used as the base
	// metadata accumulator.
	//
	// If one or more loggable objects are provided, these are deep-merged into base blob.
	//
	// Next, the event name is added to the blob under the key "event". If
	// the key "event" already exists, it will be over-written.
	//
	// Finally the timestamp and package name are added to the accumulator and
	// the metadata is logged.
	Event(ctx context.Context, event string, m ...Loggable)

	EventBegin(ctx context.Context, event string, m ...Loggable) *EventInProgress
}

EventLogger extends the StandardLogger interface to allow for log items containing structured metadata

Example
{
	log := EventLogger(nil)
	e := log.EventBegin(context.Background(), "dial")
	e.Done()
}
{
	log := EventLogger(nil)
	e := log.EventBegin(context.Background(), "dial")
	_ = e.Close() // implements io.Closer for convenience
}
Output:

func Logger

func Logger(system string) EventLogger

Logger retrieves an event logger by name

type Loggable

type Loggable interface {
	Loggable() map[string]interface{}
}

Loggable describes objects that can be marshalled into Metadata for logging

func Deferred

func Deferred(key string, f func() string) Loggable

func Pair

func Pair(key string, l Loggable) Loggable

type LoggableF

type LoggableF func() map[string]interface{}

LoggableF converts a func into a Loggable

func (LoggableF) Loggable

func (l LoggableF) Loggable() map[string]interface{}

type LoggableMap

type LoggableMap map[string]interface{}

func (LoggableMap) Loggable

func (l LoggableMap) Loggable() map[string]interface{}

type Metadata

type Metadata map[string]interface{}

Metadata is a convenience type for generic maps

func DeepMerge

func DeepMerge(b, a Metadata) Metadata

DeepMerge merges the second Metadata parameter into the first. Nested Metadata are merged recursively. Primitives are over-written.

func MetadataFromContext

func MetadataFromContext(ctx context.Context) (Metadata, error)

func Metadatify

func Metadatify(i interface{}) (Metadata, error)

Metadatify converts maps into Metadata

func Uuid

func Uuid(key string) Metadata

Uuid returns a Metadata with the string key and UUID value

func (Metadata) JsonString

func (m Metadata) JsonString() (string, error)

func (Metadata) Loggable

func (m Metadata) Loggable() map[string]interface{}

Loggable implements the Loggable interface

type MirrorWriter

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

func (*MirrorWriter) Active

func (mw *MirrorWriter) Active() (active bool)

func (*MirrorWriter) AddWriter

func (mw *MirrorWriter) AddWriter(w io.Writer)

func (*MirrorWriter) Write

func (mw *MirrorWriter) Write(b []byte) (int, error)

type Option

type Option func()

func Output

func Output(w io.Writer) Option

type PoliteJSONFormatter

type PoliteJSONFormatter struct{}

PoliteJSONFormatter marshals entries into JSON encoded slices (without overwriting user-provided keys). How polite of it!

func (*PoliteJSONFormatter) Format

func (f *PoliteJSONFormatter) Format(calldepth int, r *logging.Record, w io.Writer) error

type StandardLogger

type StandardLogger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})
	Warning(args ...interface{})
	Warningf(format string, args ...interface{})
}

StandardLogger provides API compatibility with standard printf loggers eg. go-logging

Jump to

Keyboard shortcuts

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