Documentation ¶
Overview ¶
Watermill is a Golang library for working efficiently with message streams.
It is intended for building event driven applications, enabling event sourcing, RPC over messages, sagas and basically whatever else comes to your mind.
You can use conventional pub/sub implementations like Kafka or RabbitMQ, but also HTTP or MySQL binlog if that fits your use case.
Website with detailed documentation: https://watermill.io/
Getting started guide: https://watermill.io/docs/getting-started/
Index ¶
- Constants
- func NewShortUUID() string
- func NewULID() string
- func NewUUID() string
- type CaptureLoggerAdapter
- func (c *CaptureLoggerAdapter) Captured() map[LogLevel][]CapturedMessage
- func (c *CaptureLoggerAdapter) Debug(msg string, fields LogFields)
- func (c *CaptureLoggerAdapter) Error(msg string, err error, fields LogFields)
- func (c *CaptureLoggerAdapter) Has(msg CapturedMessage) bool
- func (c *CaptureLoggerAdapter) HasError(err error) bool
- func (c *CaptureLoggerAdapter) Info(msg string, fields LogFields)
- func (c *CaptureLoggerAdapter) Trace(msg string, fields LogFields)
- func (c *CaptureLoggerAdapter) With(fields LogFields) LoggerAdapter
- type CapturedMessage
- type LogFields
- type LogLevel
- type LoggerAdapter
- type NopLogger
- type SlogLoggerAdapter
- func (s *SlogLoggerAdapter) Debug(msg string, fields LogFields)
- func (s *SlogLoggerAdapter) Error(msg string, err error, fields LogFields)
- func (s *SlogLoggerAdapter) Info(msg string, fields LogFields)
- func (s *SlogLoggerAdapter) Trace(msg string, fields LogFields)
- func (s *SlogLoggerAdapter) With(fields LogFields) LoggerAdapter
- type StdLoggerAdapter
- func (l *StdLoggerAdapter) Debug(msg string, fields LogFields)
- func (l *StdLoggerAdapter) Error(msg string, err error, fields LogFields)
- func (l *StdLoggerAdapter) Info(msg string, fields LogFields)
- func (l *StdLoggerAdapter) Trace(msg string, fields LogFields)
- func (l *StdLoggerAdapter) With(fields LogFields) LoggerAdapter
Constants ¶
const LevelTrace = slog.LevelDebug - 4
LevelTrace must be added, because slog package does not have one by default. Generate it by subtracting 4 levels from slog.Debug following the example of slog.LevelWarn and slog.LevelError which are set to 4 and 8.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CaptureLoggerAdapter ¶
type CaptureLoggerAdapter struct {
// contains filtered or unexported fields
}
CaptureLoggerAdapter is a logger which captures all logs. This logger is mostly useful for testing logging.
func NewCaptureLogger ¶
func NewCaptureLogger() *CaptureLoggerAdapter
func (*CaptureLoggerAdapter) Captured ¶
func (c *CaptureLoggerAdapter) Captured() map[LogLevel][]CapturedMessage
func (*CaptureLoggerAdapter) Debug ¶
func (c *CaptureLoggerAdapter) Debug(msg string, fields LogFields)
func (*CaptureLoggerAdapter) Error ¶
func (c *CaptureLoggerAdapter) Error(msg string, err error, fields LogFields)
func (*CaptureLoggerAdapter) Has ¶
func (c *CaptureLoggerAdapter) Has(msg CapturedMessage) bool
func (*CaptureLoggerAdapter) HasError ¶
func (c *CaptureLoggerAdapter) HasError(err error) bool
func (*CaptureLoggerAdapter) Info ¶
func (c *CaptureLoggerAdapter) Info(msg string, fields LogFields)
func (*CaptureLoggerAdapter) Trace ¶
func (c *CaptureLoggerAdapter) Trace(msg string, fields LogFields)
func (*CaptureLoggerAdapter) With ¶
func (c *CaptureLoggerAdapter) With(fields LogFields) LoggerAdapter
type CapturedMessage ¶
type LogFields ¶
type LogFields map[string]interface{}
LogFields is the logger's key-value list of fields.
type LoggerAdapter ¶
type LoggerAdapter interface { Error(msg string, err error, fields LogFields) Info(msg string, fields LogFields) Debug(msg string, fields LogFields) Trace(msg string, fields LogFields) With(fields LogFields) LoggerAdapter }
LoggerAdapter is an interface, that you need to implement to support Watermill logging. You can use StdLoggerAdapter as a reference implementation.
func NewSlogLogger ¶
func NewSlogLogger(logger *slog.Logger) LoggerAdapter
NewSlogLogger creates an adapter to the standard library's structured logging package. A `nil` logger is substituted for the result of slog.Default.
func NewStdLogger ¶
func NewStdLogger(debug, trace bool) LoggerAdapter
NewStdLogger creates StdLoggerAdapter which sends all logs to stderr.
func NewStdLoggerWithOut ¶
func NewStdLoggerWithOut(out io.Writer, debug bool, trace bool) LoggerAdapter
NewStdLoggerWithOut creates StdLoggerAdapter which sends all logs to provided io.Writer.
type NopLogger ¶
type NopLogger struct{}
NopLogger is a logger which discards all logs.
func (NopLogger) With ¶
func (l NopLogger) With(fields LogFields) LoggerAdapter
type SlogLoggerAdapter ¶
type SlogLoggerAdapter struct {
// contains filtered or unexported fields
}
SlogLoggerAdapter wraps slog.Logger.
func (*SlogLoggerAdapter) Debug ¶
func (s *SlogLoggerAdapter) Debug(msg string, fields LogFields)
Debug logs a message to slog.LevelDebug.
func (*SlogLoggerAdapter) Error ¶
func (s *SlogLoggerAdapter) Error(msg string, err error, fields LogFields)
Error logs a message to slog.LevelError.
func (*SlogLoggerAdapter) Info ¶
func (s *SlogLoggerAdapter) Info(msg string, fields LogFields)
Info logs a message to slog.LevelInfo.
func (*SlogLoggerAdapter) Trace ¶
func (s *SlogLoggerAdapter) Trace(msg string, fields LogFields)
Trace logs a message to LevelTrace.
func (*SlogLoggerAdapter) With ¶
func (s *SlogLoggerAdapter) With(fields LogFields) LoggerAdapter
With return a SlogLoggerAdapter with a set of fields injected into all consequent logging messages.
type StdLoggerAdapter ¶
type StdLoggerAdapter struct { ErrorLogger *log.Logger InfoLogger *log.Logger DebugLogger *log.Logger TraceLogger *log.Logger // contains filtered or unexported fields }
StdLoggerAdapter is a logger implementation, which sends all logs to provided standard output.
func (*StdLoggerAdapter) Debug ¶
func (l *StdLoggerAdapter) Debug(msg string, fields LogFields)
func (*StdLoggerAdapter) Error ¶
func (l *StdLoggerAdapter) Error(msg string, err error, fields LogFields)
func (*StdLoggerAdapter) Info ¶
func (l *StdLoggerAdapter) Info(msg string, fields LogFields)
func (*StdLoggerAdapter) Trace ¶
func (l *StdLoggerAdapter) Trace(msg string, fields LogFields)
func (*StdLoggerAdapter) With ¶
func (l *StdLoggerAdapter) With(fields LogFields) LoggerAdapter