diff --git a/server/configs/reload/reload.conf b/server/configs/reload/reload.conf index 4ed06709..e2aba027 100644 --- a/server/configs/reload/reload.conf +++ b/server/configs/reload/reload.conf @@ -3,8 +3,8 @@ # logging options debug: true # enable on reload trace: true # enable on reload -logtime: false -log_file: "/tmp/gnatsd.log" +logtime: true # enable on reload +log_file: "/tmp/gnatsd-2.log" # change on reload # Enable TLS on reload tls { diff --git a/server/opts.go b/server/opts.go index 59664a0f..dc75765f 100644 --- a/server/opts.go +++ b/server/opts.go @@ -712,8 +712,9 @@ func MergeOptions(fileOpts, flagOpts *Options) *Options { if flagOpts.Trace { opts.Trace = true } - if flagOpts.Logtime { - opts.Logtime = true + // Logtime flag defaults to true, so only take precedence if it was set to false. + if !flagOpts.Logtime { + opts.Logtime = false } if flagOpts.LogFile != "" { opts.LogFile = flagOpts.LogFile diff --git a/server/reload.go b/server/reload.go index c14da1c1..2ea6f96d 100644 --- a/server/reload.go +++ b/server/reload.go @@ -45,8 +45,7 @@ type traceOption struct { newValue bool } -// Apply is a no-op because authorization will be reloaded after options are -// applied +// Apply is a no-op because logging will be reloaded after options are applied. func (t *traceOption) Apply(server *Server) { server.Noticef("Reloaded: trace = %v", t.newValue) } @@ -57,12 +56,33 @@ type debugOption struct { newValue bool } -// Apply is a no-op because authorization will be reloaded after options are -// applied +// Apply is a no-op because logging will be reloaded after options are applied func (d *debugOption) Apply(server *Server) { server.Noticef("Reloaded: debug = %v", d.newValue) } +// logtimeOption implements the option interface for the `logtime` setting. +type logtimeOption struct { + loggingOption + newValue bool +} + +// Apply is a no-op because logging will be reloaded after options are applied. +func (l *logtimeOption) Apply(server *Server) { + server.Noticef("Reloaded: logtime = %v", l.newValue) +} + +// logfileOption implements the option interface for the `log_file` setting. +type logfileOption struct { + loggingOption + newValue string +} + +// Apply is a no-op because logging will be reloaded after options are applied. +func (l *logfileOption) Apply(server *Server) { + server.Noticef("Reloaded: log_file = %v", l.newValue) +} + // noopOption is a base struct that provides default no-op behaviors. type noopOption struct{} @@ -296,6 +316,10 @@ func (s *Server) diffOptions(newOpts *Options) ([]option, error) { diffOpts = append(diffOpts, &traceOption{newValue: newValue.(bool)}) case "debug": diffOpts = append(diffOpts, &debugOption{newValue: newValue.(bool)}) + case "logtime": + diffOpts = append(diffOpts, &logtimeOption{newValue: newValue.(bool)}) + case "logfile": + diffOpts = append(diffOpts, &logfileOption{newValue: newValue.(string)}) case "tlsconfig": diffOpts = append(diffOpts, &tlsOption{newValue: newValue.(*tls.Config)}) case "tlstimeout": diff --git a/server/reload_test.go b/server/reload_test.go index 94c602ba..6e70b0d5 100644 --- a/server/reload_test.go +++ b/server/reload_test.go @@ -181,6 +181,12 @@ func TestConfigReload(t *testing.T) { if !updated.Debug { t.Fatal("Expected Debug to be true") } + if !updated.Logtime { + t.Fatal("Expected Logtime to be true") + } + if updated.LogFile != "/tmp/gnatsd-2.log" { + t.Fatalf("LogFile is incorrect.\nexpected /tmp/gnatsd-2.log\ngot: %s", updated.LogFile) + } if updated.TLSConfig == nil { t.Fatal("Expected TLSConfig to be non-nil") }