Browse Source

naming updates

pull/6/head v0.5.0
lane-c-wagner 5 years ago
parent
commit
f4e9141638
5 changed files with 16 additions and 16 deletions
  1. +3
    -3
      consume.go
  2. +4
    -4
      examples/logger/main.go
  3. +6
    -6
      logger.go
  4. +2
    -2
      publish.go
  5. +1
    -1
      vendor/github.com/streadway/amqp/doc.go

+ 3
- 3
consume.go View File

@ -34,7 +34,7 @@ func NewConsumer(url string, optionFuncs ...func(*ConsumerOptions)) (Consumer, e
optionFunc(options)
}
if options.Logger == nil {
options.Logger = &nolog{} // default no logging
options.Logger = &noLogger{} // default no logging
}
chManager, err := newChannelManager(url, options.Logger)
@ -48,10 +48,10 @@ func NewConsumer(url string, optionFuncs ...func(*ConsumerOptions)) (Consumer, e
return consumer, nil
}
// WithConsumerOptionsLogging sets logging to true on the consumer options
// WithConsumerOptionsLogging sets a logger to log to stdout
func WithConsumerOptionsLogging(options *ConsumerOptions) {
options.Logging = true
options.Logger = &stdlog{}
options.Logger = &stdLogger{}
}
// WithConsumerOptionsLogger sets logging to a custom interface.


+ 4
- 4
examples/logger/main.go View File

@ -6,16 +6,16 @@ import (
rabbitmq "github.com/wagslane/go-rabbitmq"
)
// CustomLog is used in WithPublisherOptionsLogger to create a custom logger.
type CustomLog struct{}
// customLogger is used in WithPublisherOptionsLogger to create a custom logger.
type customLogger struct{}
// Printf is the only method needed in the Logger interface to function properly.
func (c *CustomLog) Printf(fmt string, args ...interface{}) {
func (c *customLogger) Printf(fmt string, args ...interface{}) {
log.Printf("mylogger: "+fmt, args...)
}
func main() {
mylogger := &CustomLog{}
mylogger := &customLogger{}
publisher, returns, err := rabbitmq.NewPublisher(
"amqp://guest:guest@localhost",


+ 6
- 6
logger.go View File

@ -13,14 +13,14 @@ type Logger interface {
const loggingPrefix = "gorabbit"
// stdlog logs to stdout using go's default logger.
type stdlog struct{}
// stdLogger logs to stdout using go's default logger.
type stdLogger struct{}
func (l stdlog) Printf(format string, v ...interface{}) {
func (l stdLogger) Printf(format string, v ...interface{}) {
log.Printf(fmt.Sprintf("%s: %s", loggingPrefix, format), v...)
}
// nolog does not log at all, this is the default.
type nolog struct{}
// noLogger does not log at all, this is the default.
type noLogger struct{}
func (l nolog) Printf(format string, v ...interface{}) {}
func (l noLogger) Printf(format string, v ...interface{}) {}

+ 2
- 2
publish.go View File

@ -98,7 +98,7 @@ type PublisherOptions struct {
// WithPublisherOptionsLogging sets logging to true on the consumer options
func WithPublisherOptionsLogging(options *PublisherOptions) {
options.Logging = true
options.Logger = &stdlog{}
options.Logger = &stdLogger{}
}
// WithPublisherOptionsLogger sets logging to a custom interface.
@ -121,7 +121,7 @@ func NewPublisher(url string, optionFuncs ...func(*PublisherOptions)) (Publisher
optionFunc(options)
}
if options.Logger == nil {
options.Logger = &nolog{} // default no logging
options.Logger = &noLogger{} // default no logging
}
chManager, err := newChannelManager(url, options.Logger)


+ 1
- 1
vendor/github.com/streadway/amqp/doc.go View File

@ -7,7 +7,7 @@
Package amqp is an AMQP 0.9.1 client with RabbitMQ extensions
Understand the AMQP 0.9.1 messaging model by reviewing these links first. Much
of the terminology in this library directly relates to AMQP concepts.
of the terminoLoggery in this library directly relates to AMQP concepts.
Resources


Loading…
Cancel
Save