Skip to content

Commit

Permalink
Merge pull request #1473 from nats-io/fix_1451
Browse files Browse the repository at this point in the history
[ADDED] Print the config file being used in startup banner
  • Loading branch information
kozlovic committed Jun 12, 2020
2 parents 02eb98c + d6de05f commit 7545ff1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/gateway_test.go
Expand Up @@ -2501,16 +2501,17 @@ func TestGatewaySendRemoteQSubs(t *testing.T) {
// Server sb1 should not have qsub in its sub interest map
checkFor(t, time.Second, 15*time.Millisecond, func() error {
var entry *sitally
var err error
sb1.gateway.pasi.Lock()
asim := sb1.gateway.pasi.m[globalAccountName]
if asim != nil {
entry = asim["foo bar"]
}
sb1.gateway.pasi.Unlock()
if entry != nil {
return fmt.Errorf("Map should not have an entry, got %#v", entry)
err = fmt.Errorf("Map should not have an entry, got %#v", entry)
}
return nil
sb1.gateway.pasi.Unlock()
return err
})

// Let's wait for A to receive the unsubscribe
Expand Down
4 changes: 4 additions & 0 deletions server/server.go
Expand Up @@ -1244,6 +1244,10 @@ func (s *Server) Start() {
// Snapshot server options.
opts := s.getOpts()

if opts.ConfigFile != _EMPTY_ {
s.Noticef("Using configuration file: %s", opts.ConfigFile)
}

hasOperators := len(opts.TrustedOperators) > 0
if hasOperators {
s.Noticef("Trusted Operators")
Expand Down
34 changes: 34 additions & 0 deletions server/server_test.go
Expand Up @@ -1747,3 +1747,37 @@ func TestReconnectErrorReports(t *testing.T) {
})
}
}

func TestServerLogsConfigurationFile(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "_nats-server")
if err != nil {
t.Fatal("Could not create tmp dir")
}
defer os.RemoveAll(tmpDir)

file, err := ioutil.TempFile(tmpDir, "nats_server_log_")
if err != nil {
t.Fatalf("Could not create the temp file: %v", err)
}
file.Close()

conf := createConfFile(t, []byte(fmt.Sprintf(`
port: -1
logfile: "%s"
`, file.Name())))
defer os.Remove(conf)

o := LoadConfig(conf)
o.ConfigFile = file.Name()
o.NoLog = false
s := RunServer(o)
s.Shutdown()

log, err := ioutil.ReadFile(file.Name())
if err != nil {
t.Fatalf("Error reading log file: %v", err)
}
if !bytes.Contains(log, []byte(fmt.Sprintf("Using configuration file: %s", file.Name()))) {
t.Fatalf("Config file location was not reported in log: %s", log)
}
}

0 comments on commit 7545ff1

Please sign in to comment.