xlog

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StdoutFile = "stdout"

	LevelNone  = ""
	LevelError = "ERROR"
	LevelWarn  = "WARN"
	LevelInfo  = "INFO"
	LevelDebug = "DEBUG"
)

Variables

This section is empty.

Functions

func AllowLevel

func AllowLevel(next log.Logger, v string) (log.Logger, error)

AllowLevel produces a filtered logger with the given level.AllowXXX set.

func Default

func Default() log.Logger

Default() returns the singleton default go-kit logger, which writes to stdout and is safe for concurrent usage.

func Error added in v0.0.3

func Error() log.Logger

Error returns a default go-kit Logger that sends all output to os.Stderr. Useful for reporting errors on a crash.

func ErrorKey

func ErrorKey() interface{}

ErrorKey returns the logging key for error text

func Get

func Get(ctx context.Context) log.Logger

func GetDefault

func GetDefault(ctx context.Context, d log.Logger) log.Logger

func Level

func Level(v string) (level.Value, error)

Level returns the go-kit level.Value for a given configuration string value.

func Logger added in v0.0.3

func Logger() fx.Option

Logger is an analogue to the fx.Logger option. This function creates a BufferedPrinter and emits it as a component, sets it as the uber/fx logger, and adds it as an error handler. Other code can express a dependency on a *BufferedPrinter and set the logger.

func MessageKey

func MessageKey() interface{}

MessageKey returns the logging key for an arbitrary message

func New

func New(o Options) (log.Logger, error)

New produces a go-kit log.Logger using the given set of configuration options

func Provide

func Provide(logger log.Logger) func() log.Logger

Provide takes a preexising logger and emits it as a component. Useful when an external logger should be available in a container as a component.

func TimestampKey

func TimestampKey() interface{}

TimestampKey returns the logging key for the timestamp

func Unmarshal

func Unmarshal(key string) func(LogUnmarshalIn) (log.Logger, error)

Unmarshal returns an uber/fx provider function that handles unmarshalling a logger and emitted it as a component. If a *BufferedPrinter component is present, the unmarshalled logger will be set as that printer's logger.

func With

func With(ctx context.Context, l log.Logger) context.Context

Types

type BufferedPrinter added in v0.0.3

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

BufferedPrinter is an uber/fx Printer that buffers log messages until a go-kit Logger is established. This type is useful when a go-kit Logger is created as an uber/fx component and that Logger component should be used for all output.

func (*BufferedPrinter) HandleError added in v0.0.3

func (bp *BufferedPrinter) HandleError(err error)

HandleError logs an error through the established logger. If no logger has been set yet, the Error() logger is used.

func (*BufferedPrinter) Len added in v0.0.3

func (bp *BufferedPrinter) Len() (c int)

Len returns the count of messages currently buffered. This will always be zero after SetLogger has been called.

func (*BufferedPrinter) OnStart added in v0.0.3

func (bp *BufferedPrinter) OnStart(context.Context) error

OnStart ensures that any messages are flushed to avoid holding onto them during application execution

func (*BufferedPrinter) Printf added in v0.0.3

func (bp *BufferedPrinter) Printf(format string, parameters ...interface{})

func (*BufferedPrinter) SetLogger added in v0.0.3

func (bp *BufferedPrinter) SetLogger(l log.Logger)

SetLogger establishes the go-kit Logger that should receive uber/fx output. Any buffered messages are immediately to the supplied logger. All calls to Printf afterward will not be buffered but sent to the supplied logger.

This method is idempotent. Subsequent attempts to set the logger have no effect and output will continue to the original logger.

type DiscardPrinter added in v0.0.3

type DiscardPrinter struct{}

DiscardPrinter is an fx.Printer that simply throws away all printed messages. This type is primarily useful for tests which don't need or want any output from uber/fx itself.

func (DiscardPrinter) Printf added in v0.0.3

func (dp DiscardPrinter) Printf(string, ...interface{})

type LogUnmarshalIn added in v0.0.3

type LogUnmarshalIn struct {
	fx.In

	// Unmarshaller is the required strategy for unmarshalling an Options
	Unmarshaller config.Unmarshaller

	// Printer is the optional BufferedPrinter component.  If present, the unmarshalled logger
	// will be set as this printer's logger.
	Printer *BufferedPrinter `optional:"true"`
}

LogUnmarshalIn defines the set of dependencies for unmarshalling a go-kit logger

type Options

type Options struct {
	// File is the output destination for logs.  If unset or set to StdoutFile,
	// a console logger is created and the log rolling options are ignored.
	File string

	// Level is the max logging level for output.
	Level string

	// MaxSize is the lumberjack maximum size when rolling logs
	MaxSize int

	// MaxBackups is the lumberjack maximum backs when rolling logs
	MaxBackups int

	// MaxAge is the lumberjack maximum age when rolling logs
	MaxAge int

	// JSON indicates whether a go-kit JSON logger or a logfmt logger is used
	JSON bool
}

Options defines the set of configuration options for a go-kit log.LoggeAr.

type Printer

type Printer struct {
	Logger log.Logger
}

Printer adapts a go-kit Logger onto the fx.Printer interface. Use this type to direct uber/fx app logging to an externally created go-kit Logger.

func (Printer) Printf

func (p Printer) Printf(format string, parameters ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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