Skip to content

Commit

Permalink
Use named loggers everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
weeco committed Aug 16, 2021
1 parent 1545c20 commit ba20914
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions kafka/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ type Service struct {
func NewService(cfg Config, logger *zap.Logger) *Service {
return &Service{
cfg: cfg,
logger: logger.Named("kafka-service"),
logger: logger.Named("kafka_service"),
}
}

// CreateAndTestClient creates a client with the services default settings
// logger: will be used to log connections, errors, warnings about tls config, ...
func (s *Service) CreateAndTestClient(ctx context.Context, logger *zap.Logger, opts []kgo.Opt) (*kgo.Client, error) {
func (s *Service) CreateAndTestClient(ctx context.Context, l *zap.Logger, opts []kgo.Opt) (*kgo.Client, error) {
logger := l.Named("kgo_client")
// Config with default options
kgoOpts, err := NewKgoConfig(s.cfg, logger)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
startupLogger.Fatal("failed to parse config", zap.Error(err))
}

logger := logging.NewLogger(cfg.Logger, cfg.Exporter.Namespace)
logger := logging.NewLogger(cfg.Logger, cfg.Exporter.Namespace).Named("main")
if err != nil {
startupLogger.Fatal("failed to create new logger", zap.Error(err))
}
Expand Down
5 changes: 2 additions & 3 deletions minion/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func NewService(cfg Config, logger *zap.Logger, kafkaSvc *kafka.Service, metrics
}

// Kafka client
hooksChildLogger := logger.With(zap.String("source", "minion_kafka_client"))
minionHooks := newMinionClientHooks(hooksChildLogger, metricsNamespace)
minionHooks := newMinionClientHooks(logger.Named("kafka_hooks"), metricsNamespace)
kgoOpts := []kgo.Opt{
kgo.WithHooks(minionHooks),
kgo.ConsumeTopics("__consumer_offsets"),
Expand All @@ -63,7 +62,7 @@ func NewService(cfg Config, logger *zap.Logger, kafkaSvc *kafka.Service, metrics

service := &Service{
Cfg: cfg,
logger: logger,
logger: logger.Named("minion_service"),

requestGroup: &singleflight.Group{},
cache: make(map[string]interface{}),
Expand Down
2 changes: 1 addition & 1 deletion minion/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type OffsetCommit struct {

func newStorage(logger *zap.Logger) (*Storage, error) {
return &Storage{
logger: logger,
logger: logger.Named("storage"),
offsetCommits: cmap.New(),
progressTracker: cmap.New(),
isReadyBool: atomic.NewBool(false),
Expand Down
2 changes: 1 addition & 1 deletion prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Exporter struct {
}

func NewExporter(cfg Config, logger *zap.Logger, minionSvc *minion.Service) (*Exporter, error) {
return &Exporter{cfg: cfg, logger: logger, minionSvc: minionSvc}, nil
return &Exporter{cfg: cfg, logger: logger.Named("prometheus"), minionSvc: minionSvc}, nil
}

func (e *Exporter) InitializeMetrics() {
Expand Down

0 comments on commit ba20914

Please sign in to comment.