Documentation ¶
Index ¶
- Constants
- func AllowLevel(next log.Logger, v string) (log.Logger, error)
- func Default() log.Logger
- func Error() log.Logger
- func ErrorKey() interface{}
- func Get(ctx context.Context) log.Logger
- func GetDefault(ctx context.Context, d log.Logger) log.Logger
- func Level(v string) (level.Value, error)
- func Logger() fx.Option
- func MessageKey() interface{}
- func New(o Options) (log.Logger, error)
- func Provide(logger log.Logger) func() log.Logger
- func TimestampKey() interface{}
- func Unmarshal(key string) func(LogUnmarshalIn) (log.Logger, error)
- func With(ctx context.Context, l log.Logger) context.Context
- type BufferedPrinter
- type DiscardPrinter
- type LogUnmarshalIn
- type Options
- type Printer
Constants ¶
const ( StdoutFile = "stdout" LevelNone = "" LevelError = "ERROR" LevelWarn = "WARN" LevelInfo = "INFO" LevelDebug = "DEBUG" )
Variables ¶
This section is empty.
Functions ¶
func AllowLevel ¶
AllowLevel produces a filtered logger with the given level.AllowXXX set.
func Default ¶
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
Error returns a default go-kit Logger that sends all output to os.Stderr. Useful for reporting errors on a crash.
func Logger ¶ added in v0.0.3
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 Provide ¶
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.
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.