Pass a logger arg to `NewClient` and `NewServer`

This commit is contained in:
Sean Chittenden 2016-06-16 23:29:23 -07:00
parent c2f96ee6ba
commit 9a60999100
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
5 changed files with 15 additions and 17 deletions

View File

@ -144,10 +144,7 @@ type Client struct {
}
// NewClient is used to create a new client from the given configuration
func NewClient(cfg *config.Config, consulSyncer *consul.Syncer) (*Client, error) {
// Create a logger
logger := log.New(cfg.LogOutput, "", log.LstdFlags)
func NewClient(cfg *config.Config, consulSyncer *consul.Syncer, logger *log.Logger) (*Client, error) {
// Create the client
c := &Client{
config: cfg,

View File

@ -61,13 +61,14 @@ func testServer(t *testing.T, cb func(*nomad.Config)) (*nomad.Server, string) {
}
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 {
t.Fatalf("err: %v", err)
}
// Create server
server, err := nomad.NewServer(config, consulSyncer)
server, err := nomad.NewServer(config, consulSyncer, logger)
if err != nil {
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)
}
client, err := NewClient(conf, consulSyncer)
logger := log.New(conf.LogOutput, "", log.LstdFlags)
client, err := NewClient(conf, consulSyncer, logger)
if err != nil {
t.Fatalf("err: %v", err)
}
@ -475,12 +477,13 @@ func TestClient_SaveRestoreState(t *testing.T) {
// Create a new client
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 {
t.Fatalf("err: %v", err)
}
c2, err := NewClient(c1.config, consulSyncer)
c2, err := NewClient(c1.config, consulSyncer, logger)
if err != nil {
t.Fatalf("err: %v", err)
}

View File

@ -388,7 +388,7 @@ func (a *Agent) setupServer() error {
}
// Create the server
server, err := nomad.NewServer(conf, a.consulSyncer)
server, err := nomad.NewServer(conf, a.consulSyncer, a.logger)
if err != nil {
return fmt.Errorf("server setup failed: %v", err)
}
@ -467,7 +467,7 @@ func (a *Agent) setupClient() error {
}
// Create the client
client, err := client.NewClient(conf, a.consulSyncer)
client, err := client.NewClient(conf, a.consulSyncer, a.logger)
if err != nil {
return fmt.Errorf("client setup failed: %v", err)
}

View File

@ -164,7 +164,7 @@ type endpoints struct {
// NewServer is used to construct a new Nomad server from the
// 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
if err := config.CheckVersion(); err != nil {
return nil, err
@ -175,9 +175,6 @@ func NewServer(config *Config, consulSyncer *consul.Syncer) (*Server, error) {
config.LogOutput = os.Stderr
}
// Create a logger
logger := log.New(config.LogOutput, "", log.LstdFlags)
// Create an eval broker
evalBroker, err := NewEvalBroker(config.EvalNackTimeout, config.EvalDeliveryLimit)
if err != nil {

View File

@ -66,13 +66,14 @@ func testServer(t *testing.T, cb func(*Config)) *Server {
config.RaftConfig.StartAsLeader = !config.DevDisableBootstrap
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 {
t.Fatalf("err: %v", err)
}
// Create server
server, err := NewServer(config, consulSyncer)
server, err := NewServer(config, consulSyncer, logger)
if err != nil {
t.Fatalf("err: %v", err)
}