Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inherit debug logging to custom loggers, fixes issue #382 #383

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ import (
"github.com/Shopify/sarama"
)

var (
defaultLogger = &std{
log: log.New(os.Stderr, "", log.LstdFlags),
}
)
var defaultLogger = &std{
log: log.New(os.Stderr, "", log.LstdFlags),
}

// Logger is the interface Goka and its subpackages use for logging.
type Logger interface {

// Print will simply print the params
Print(...interface{})

Expand Down Expand Up @@ -53,6 +50,7 @@ type std struct {
func (s *std) Print(msgs ...interface{}) {
s.log.Print(msgs...)
}

func (s *std) Println(msgs ...interface{}) {
s.log.Print(msgs...)
}
Expand All @@ -77,6 +75,7 @@ func DefaultLogger() Logger {
}

// Debug enables or disables debug logging using the global logger.
// The goka debugging setting is applied to any custom loggers in goka components (Processors, Views, Emitters).
func Debug(gokaDebug, saramaDebug bool) {
defaultLogger.debug = gokaDebug
if saramaDebug {
Expand All @@ -89,15 +88,17 @@ func SetSaramaLogger(logger Logger) {
}

// newLogger creates a new goka logger
func wrapLogger(l Logger) logger {
func wrapLogger(l Logger, debug bool) logger {
return &std{
log: l,
log: l,
debug: debug,
}
}

func (s *std) CurrentPrefix() string {
return s.prefix
}

func (s *std) StackPrefix(prefix string) logger {
var prefPath []string
// append existing path
Expand Down
7 changes: 3 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func DefaultHasher() func() hash.Hash32 {
return func() hash.Hash32 {
return fnv.New32a()
}

}

// DefaultUpdateContext implements the UpdateContext interface.
Expand Down Expand Up @@ -221,7 +220,7 @@ func WithLogger(l Logger) ProcessorOption {
if prefixLogger, ok := l.(logger); ok {
o.log = prefixLogger
} else {
o.log = wrapLogger(l)
o.log = wrapLogger(l, defaultLogger.debug)
}
}
}
Expand Down Expand Up @@ -406,7 +405,7 @@ func WithViewLogger(l Logger) ViewOption {
if prefixLogger, ok := l.(logger); ok {
o.log = prefixLogger
} else {
o.log = wrapLogger(l)
o.log = wrapLogger(l, defaultLogger.debug)
}
}
}
Expand Down Expand Up @@ -555,7 +554,7 @@ func WithEmitterLogger(l Logger) EmitterOption {
if prefixLogger, ok := l.(logger); ok {
o.log = prefixLogger
} else {
o.log = wrapLogger(l)
o.log = wrapLogger(l, defaultLogger.debug)
}
}
}
Expand Down