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) PrintCaptured(t Logfer)
- func (c *CaptureLoggerAdapter) Trace(msg string, fields LogFields)
- func (c *CaptureLoggerAdapter) With(fields LogFields) LoggerAdapter
- type CapturedMessage
- type LogFields
- type LogLevel
- type Logfer
- type LoggerAdapter
- func NewSlogLogger(logger *slog.Logger) LoggerAdapter
- func NewSlogLoggerWithLevelMapping(logger *slog.Logger, watermillLevelToSlog map[slog.Level]slog.Level) LoggerAdapter
- func NewStdLogger(debug, trace bool) LoggerAdapter
- func NewStdLoggerWithOut(out io.Writer, debug bool, trace bool) 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 ¶
func NewShortUUID ¶ added in v0.3.0
func NewShortUUID() string
NewShortUUID returns a new short UUID.
Types ¶
type CaptureLoggerAdapter ¶ added in v0.3.0
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 ¶ added in v0.3.0
func NewCaptureLogger() *CaptureLoggerAdapter
func (*CaptureLoggerAdapter) Captured ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) Captured() map[LogLevel][]CapturedMessage
func (*CaptureLoggerAdapter) Debug ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) Debug(msg string, fields LogFields)
func (*CaptureLoggerAdapter) Error ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) Error(msg string, err error, fields LogFields)
func (*CaptureLoggerAdapter) Has ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) Has(msg CapturedMessage) bool
func (*CaptureLoggerAdapter) HasError ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) HasError(err error) bool
func (*CaptureLoggerAdapter) Info ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) Info(msg string, fields LogFields)
func (*CaptureLoggerAdapter) PrintCaptured ¶ added in v1.4.3
func (c *CaptureLoggerAdapter) PrintCaptured(t Logfer)
func (*CaptureLoggerAdapter) Trace ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) Trace(msg string, fields LogFields)
func (*CaptureLoggerAdapter) With ¶ added in v0.3.0
func (c *CaptureLoggerAdapter) With(fields LogFields) LoggerAdapter
type CapturedMessage ¶ added in v0.3.0
func (CapturedMessage) ContentEquals ¶ added in v1.4.3
func (c CapturedMessage) ContentEquals(other CapturedMessage) bool
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 ¶ added in v1.3.5
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 NewSlogLoggerWithLevelMapping ¶ added in v1.4.0
func NewSlogLoggerWithLevelMapping(logger *slog.Logger, watermillLevelToSlog map[slog.Level]slog.Level) LoggerAdapter
NewSlogLoggerWithLevelMapping creates an adapter to the standard library's structured logging package. A `nil` logger is substituted for the result of slog.Default. The `watermillLevelToSlog` parameter is a map that maps Watermill's log levels to the levels of the structured logger. It's helpful, when want to for example log Watermill's info logs as debug in slog.
func NewStdLogger ¶
func NewStdLogger(debug, trace bool) LoggerAdapter
NewStdLogger creates StdLoggerAdapter which sends all logs to stderr.
func NewStdLoggerWithOut ¶ added in v0.3.0
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 ¶ added in v0.3.0
func (l NopLogger) With(fields LogFields) LoggerAdapter
type SlogLoggerAdapter ¶ added in v1.3.5
type SlogLoggerAdapter struct {
// contains filtered or unexported fields
}
SlogLoggerAdapter wraps slog.Logger.
func (*SlogLoggerAdapter) Debug ¶ added in v1.3.5
func (s *SlogLoggerAdapter) Debug(msg string, fields LogFields)
Debug logs a message to slog.LevelDebug.
func (*SlogLoggerAdapter) Error ¶ added in v1.3.5
func (s *SlogLoggerAdapter) Error(msg string, err error, fields LogFields)
Error logs a message to slog.LevelError.
func (*SlogLoggerAdapter) Info ¶ added in v1.3.5
func (s *SlogLoggerAdapter) Info(msg string, fields LogFields)
Info logs a message to slog.LevelInfo.
func (*SlogLoggerAdapter) Trace ¶ added in v1.3.5
func (s *SlogLoggerAdapter) Trace(msg string, fields LogFields)
Trace logs a message to LevelTrace.
func (*SlogLoggerAdapter) With ¶ added in v1.3.5
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 ¶ added in v0.3.0
func (l *StdLoggerAdapter) With(fields LogFields) LoggerAdapter
Directories ¶
Path | Synopsis |
---|---|
_examples
|
|
components
|
|
dev
|
|
update-examples-deps
Module
|
|
validate-examples
Module
|
|
wait-for
Module
|
|
docs
|
|
tools
|
|
mill
Module
|
|
pq
Module
|