Beispiel #1
0
func (s *GlobalSuite) TestConfigureLoggers(c *gc.C) {
	err := loggo.ConfigureLoggers("testing.module=debug")
	c.Assert(err, gc.IsNil)
	expected := "<root>=WARNING;testing.module=DEBUG"
	c.Assert(loggo.DefaultContext().Config().String(), gc.Equals, expected)
	c.Assert(loggo.LoggerInfo(), gc.Equals, expected)
}
Beispiel #2
0
func (s *LoggerSuite) TestInitialState(c *gc.C) {
	config, err := s.State.ModelConfig()
	c.Assert(err, jc.ErrorIsNil)
	expected := config.LoggingConfig()

	initial := "<root>=DEBUG;wibble=ERROR"
	c.Assert(expected, gc.Not(gc.Equals), initial)

	loggo.DefaultContext().ResetLoggerLevels()
	err = loggo.ConfigureLoggers(initial)
	c.Assert(err, jc.ErrorIsNil)

	loggingWorker, _ := s.makeLogger(c)
	defer worker.Stop(loggingWorker)

	s.waitLoggingInfo(c, expected)
}
Beispiel #3
0
func (logger *Logger) setLogging() {
	loggingConfig, err := logger.api.LoggingConfig(logger.agentConfig.Tag())
	if err != nil {
		log.Errorf("%v", err)
	} else {
		if loggingConfig != logger.lastConfig {
			log.Debugf("reconfiguring logging from %q to %q", logger.lastConfig, loggingConfig)
			loggo.DefaultContext().ResetLoggerLevels()
			if err := loggo.ConfigureLoggers(loggingConfig); err != nil {
				// This shouldn't occur as the loggingConfig should be
				// validated by the original Config before it gets here.
				log.Warningf("configure loggers failed: %v", err)
				// Try to reset to what we had before
				loggo.ConfigureLoggers(logger.lastConfig)
			}
			logger.lastConfig = loggingConfig
		}
	}
}
Beispiel #4
0
func (s *ConfigSuite) SetUpTest(c *gc.C) {
	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
	// Make sure that the defaults are used, which
	// is <root>=WARNING
	loggo.DefaultContext().ResetLoggerLevels()
}
Beispiel #5
0
func (*GlobalSuite) TestRemoveWriter(c *gc.C) {
	oldWriter, err := loggo.RemoveWriter("default")
	c.Assert(oldWriter, gc.NotNil)
	c.Assert(err, gc.IsNil)
	c.Assert(loggo.DefaultContext().WriterNames(), gc.HasLen, 0)
}
Beispiel #6
0
func (*GlobalSuite) TestReplaceDefaultWriter(c *gc.C) {
	oldWriter, err := loggo.ReplaceDefaultWriter(&writer{})
	c.Assert(oldWriter, gc.NotNil)
	c.Assert(err, gc.IsNil)
	c.Assert(loggo.DefaultContext().WriterNames(), gc.DeepEquals, []string{"default"})
}