mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 11:48:43 -07:00
Add support for reloading logtime and log_file
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user