Permalink
Browse files

Clear loggers in steno.Init()

NewLogger() defaults BaseLogger.level to Config.Level
but if we want to re-read config from disk for example and
Config.Level changes, this is not propagated to existing loggers.

Assuming Config.Init() is meant to be called when config is read
from disk, such as process start or SIGHUP style restart, seems
clearing the loggers map in Config.Init() is reasonable.

Change-Id: I999238e157f379924da63f4f06440b15ad4598b6
  • Loading branch information...
1 parent a3a577a commit 4a116e248410f7e7c878ea089738bb4072edc35e @dougm dougm committed Oct 2, 2012
Showing with 24 additions and 0 deletions.
  1. +20 −0 config_test.go
  2. +4 −0 steno.go
View
@@ -0,0 +1,20 @@
+package steno
+
+import (
+ . "launchpad.net/gocheck"
+)
+
+type ConfigSuite struct {
+}
+
+var _ = Suite(&ConfigSuite{})
+
+func (s *ConfigSuite) TestReInitLevel(c *C) {
+ levels := []*LogLevel{LOG_INFO, LOG_DEBUG, LOG_WARN}
+
+ for _, level := range levels {
+ Init(&Config{Level: level})
+ logger := NewLogger("reinit").(*BaseLogger)
+ c.Assert(logger.level, Equals, level)
+ }
+}
View
@@ -36,6 +36,10 @@ func Init(c *Config) {
if config.Port > 0 {
initHttpServer(config.Port)
}
+
+ for name, _ := range loggers {
+ loggers[name] = nil
+ }
}
func NewLogger(name string) Logger {

0 comments on commit 4a116e2

Please sign in to comment.