Beispiel #1
0
func (s *nameUtilsSuite) TestGetConfigParamName(c *C) {
	ctx, ok := getConfigParamName("abc", "context", nil)
	c.Assert(ok, Equals, false)

	ctx, ok = getConfigParamName("abc.asd.ab", "context", nil)
	c.Assert(ok, Equals, false)

	ctx, ok = getConfigParamName("context.test", "context", nil)
	c.Assert(ok, Equals, true)
	c.Assert(ctx, Equals, "")

	ctx, ok = getConfigParamName("context..test", "context", nil)
	c.Assert(ok, Equals, true)
	c.Assert(ctx, Equals, "")

	panicTest := gorivets.CheckPanic(func() { getConfigParamName("appender..test", "appender", isCorrectAppenderName) })
	c.Assert(panicTest, NotNil)

	ctx, ok = getConfigParamName("context...test", "context", nil)
	c.Assert(ok, Equals, true)
	c.Assert(ctx, Equals, ".")

	ctx, ok = getConfigParamName("context.test.text", "context", nil)
	c.Assert(ok, Equals, true)
	c.Assert(ctx, Equals, "test")

	ctx, ok = getConfigParamName("context.a.b.c.test", "context", nil)
	c.Assert(ok, Equals, true)
	c.Assert(ctx, Equals, "a.b.c")
}
Beispiel #2
0
func panicWhenApplyLevelParams(c *C, lc *logConfig, params map[string]string) {
	pnc := gorivets.CheckPanic(
		func() {
			lc.applyLevelParams(params)
		})
	c.Assert(pnc, NotNil)
}
Beispiel #3
0
func panicWhenCreateContext(c *C, lc *logConfig, params map[string]string) {
	pnc := gorivets.CheckPanic(
		func() {
			lc.createContexts(params)
		})
	c.Assert(pnc, NotNil)
}
Beispiel #4
0
func (s *logConfigSuite) TestCreateAppenders(c *C) {
	lc := newLogConfig()
	c.Assert(lc.registerAppender(&testAppenderFactory{consoleAppenderName}), IsNil)
	lc.initIfNeeded()

	lc.createAppenders(nil)
	lc.createAppenders(map[string]string{"appender.ROOT.type": consoleAppenderName})

	pnc := gorivets.CheckPanic(
		func() {
			lc.createAppenders(map[string]string{"appender.ROOT.type": "unknown appender"})
		})
	c.Assert(pnc, NotNil)

	pnc = gorivets.CheckPanic(
		func() {
			lc.createAppenders(map[string]string{"appender.ROOT.layot": "unknown layout %$"})
		})
	c.Assert(pnc, NotNil)
}
Beispiel #5
0
func (s *logConfigSuite) TestCreateLoggers(c *C) {
	lc := newLogConfig()
	c.Assert(lc.registerAppender(&testAppenderFactory{consoleAppenderName}), IsNil)
	lc.initIfNeeded()

	params := map[string]string{
		"logger.a.b.c.level": "TRACE",
		"logger.b.c.d.level": "DEBUG",
	}
	lc.createLoggers(params)
	c.Assert(lc.getLogger("a.b.c").(*logger).logLevel, Equals, TRACE)
	c.Assert(lc.getLogger("b.c.d").(*logger).logLevel, Equals, DEBUG)

	pnc := gorivets.CheckPanic(
		func() {
			lc.createLoggers(map[string]string{
				"logger.a.b.c.level": "ABC",
			})
		})
	c.Assert(pnc, NotNil)
}
Beispiel #6
0
func (s *logConfigSuite) TestGetAppendersFromList(c *C) {
	lc := newLogConfig()

	lc.appenders["a"] = &testAppender{"a"}
	lc.appenders["b"] = &testAppender{"b"}
	lc.appenders["c"] = &testAppender{"c"}

	ok := gorivets.CheckPanic(func() { lc.getAppendersFromList("e") })
	c.Assert(ok, NotNil)

	apps := lc.getAppendersFromList("  ")
	c.Assert(len(apps), Equals, 0)

	apps = lc.getAppendersFromList("b")
	c.Assert(len(apps), Equals, 1)
	c.Assert(apps[0], NotNil)

	apps = lc.getAppendersFromList(" c, a")
	c.Assert(len(apps), Equals, 2)
	c.Assert(apps[0].(*testAppender).name, Equals, "c")
	c.Assert(apps[1].(*testAppender).name, Equals, "a")
}