Pass a logger arg to `NewClient` and `NewServer`
This commit is contained in:
parent
c2f96ee6ba
commit
9a60999100
|
@ -144,10 +144,7 @@ type Client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient is used to create a new client from the given configuration
|
// NewClient is used to create a new client from the given configuration
|
||||||
func NewClient(cfg *config.Config, consulSyncer *consul.Syncer) (*Client, error) {
|
func NewClient(cfg *config.Config, consulSyncer *consul.Syncer, logger *log.Logger) (*Client, error) {
|
||||||
// Create a logger
|
|
||||||
logger := log.New(cfg.LogOutput, "", log.LstdFlags)
|
|
||||||
|
|
||||||
// Create the client
|
// Create the client
|
||||||
c := &Client{
|
c := &Client{
|
||||||
config: cfg,
|
config: cfg,
|
||||||
|
|
|
@ -61,13 +61,14 @@ func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdownCh := make(chan struct{})
|
shutdownCh := make(chan struct{})
|
||||||
consulSyncer, err := consul.NewSyncer(config.ConsulConfig, shutdownCh, log.New(os.Stderr, "", log.LstdFlags))
|
logger := log.New(config.LogOutput, "", log.LstdFlags)
|
||||||
|
consulSyncer, err := consul.NewSyncer(config.ConsulConfig, shutdownCh, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create server
|
// Create server
|
||||||
server, err := nomad.NewServer(config, consulSyncer)
|
server, err := nomad.NewServer(config, consulSyncer, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +88,8 @@ func testClient(t *testing.T, cb func(c *config.Config)) *Client {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := NewClient(conf, consulSyncer)
|
logger := log.New(conf.LogOutput, "", log.LstdFlags)
|
||||||
|
client, err := NewClient(conf, consulSyncer, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -475,12 +477,13 @@ func TestClient_SaveRestoreState(t *testing.T) {
|
||||||
|
|
||||||
// Create a new client
|
// Create a new client
|
||||||
shutdownCh := make(chan struct{})
|
shutdownCh := make(chan struct{})
|
||||||
consulSyncer, err := consul.NewSyncer(c1.config.ConsulConfig, shutdownCh, log.New(os.Stderr, "", log.LstdFlags))
|
logger := log.New(config.LogOutput, "", log.LstdFlags)
|
||||||
|
consulSyncer, err := consul.NewSyncer(c1.config.ConsulConfig, shutdownCh, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c2, err := NewClient(c1.config, consulSyncer)
|
c2, err := NewClient(c1.config, consulSyncer, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,7 +388,7 @@ func (a *Agent) setupServer() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the server
|
// Create the server
|
||||||
server, err := nomad.NewServer(conf, a.consulSyncer)
|
server, err := nomad.NewServer(conf, a.consulSyncer, a.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("server setup failed: %v", err)
|
return fmt.Errorf("server setup failed: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,7 @@ func (a *Agent) setupClient() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the client
|
// Create the client
|
||||||
client, err := client.NewClient(conf, a.consulSyncer)
|
client, err := client.NewClient(conf, a.consulSyncer, a.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("client setup failed: %v", err)
|
return fmt.Errorf("client setup failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ type endpoints struct {
|
||||||
|
|
||||||
// NewServer is used to construct a new Nomad server from the
|
// NewServer is used to construct a new Nomad server from the
|
||||||
// configuration, potentially returning an error
|
// configuration, potentially returning an error
|
||||||
func NewServer(config *Config, consulSyncer *consul.Syncer) (*Server, error) {
|
func NewServer(config *Config, consulSyncer *consul.Syncer, logger *log.Logger) (*Server, error) {
|
||||||
// Check the protocol version
|
// Check the protocol version
|
||||||
if err := config.CheckVersion(); err != nil {
|
if err := config.CheckVersion(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -175,9 +175,6 @@ func NewServer(config *Config, consulSyncer *consul.Syncer) (*Server, error) {
|
||||||
config.LogOutput = os.Stderr
|
config.LogOutput = os.Stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a logger
|
|
||||||
logger := log.New(config.LogOutput, "", log.LstdFlags)
|
|
||||||
|
|
||||||
// Create an eval broker
|
// Create an eval broker
|
||||||
evalBroker, err := NewEvalBroker(config.EvalNackTimeout, config.EvalDeliveryLimit)
|
evalBroker, err := NewEvalBroker(config.EvalNackTimeout, config.EvalDeliveryLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -66,13 +66,14 @@ func testServer(t *testing.T, cb func(*Config)) *Server {
|
||||||
config.RaftConfig.StartAsLeader = !config.DevDisableBootstrap
|
config.RaftConfig.StartAsLeader = !config.DevDisableBootstrap
|
||||||
|
|
||||||
shutdownCh := make(chan struct{})
|
shutdownCh := make(chan struct{})
|
||||||
consulSyncer, err := consul.NewSyncer(config.ConsulConfig, shutdownCh, log.New(config.LogOutput, "", log.LstdFlags))
|
logger := log.New(config.LogOutput, "", log.LstdFlags)
|
||||||
|
consulSyncer, err := consul.NewSyncer(config.ConsulConfig, shutdownCh, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create server
|
// Create server
|
||||||
server, err := NewServer(config, consulSyncer)
|
server, err := NewServer(config, consulSyncer, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue