Skip to content

Commit

Permalink
refactor: check logger is nil or not when creating connection manager (
Browse files Browse the repository at this point in the history
  • Loading branch information
Newt6611 authored Nov 14, 2024
1 parent bc66642 commit a109c4e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions connmanager/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package connmanager

import (
"fmt"
"io"
"log/slog"
"sync"

Expand Down Expand Up @@ -81,6 +82,9 @@ type ConnectionManagerHost struct {
}

func NewConnectionManager(cfg ConnectionManagerConfig) *ConnectionManager {
if cfg.Logger == nil {
cfg.Logger = slog.New(slog.NewJSONHandler(io.Discard, nil))
}
return &ConnectionManager{
config: cfg,
connections: make(
Expand All @@ -103,15 +107,15 @@ func (c *ConnectionManager) AddHost(
Port: port,
Tags: tmpTags,
}
if c.config.Logger != nil {
c.config.Logger.Debug(
fmt.Sprintf(
"connmanager: adding host: %+v",
cmHost,
),
"component", "connmanager",
)
}

c.config.Logger.Debug(
fmt.Sprintf(
"connmanager: adding host: %+v",
cmHost,
),
"component", "connmanager",
)

c.hosts = append(
c.hosts,
cmHost,
Expand Down

0 comments on commit a109c4e

Please sign in to comment.