HTRACE-290. htraced: Fix per-faculty log level settings and add unit tests for conditional logging (Masatake Iwasaki via Colin P. McCabe)
diff --git a/htrace-htraced/go/src/org/apache/htrace/common/log.go b/htrace-htraced/go/src/org/apache/htrace/common/log.go
index c29195e..2e3e267 100644
--- a/htrace-htraced/go/src/org/apache/htrace/common/log.go
+++ b/htrace-htraced/go/src/org/apache/htrace/common/log.go
@@ -194,7 +194,7 @@
 	} else {
 		facultyLogPath = cnf.Get(conf.HTRACE_LOG_PATH)
 	}
-	facultyLogLevelKey := faculty + conf.HTRACE_LOG_LEVEL
+	facultyLogLevelKey := faculty + "." + conf.HTRACE_LOG_LEVEL
 	var facultyLogLevelStr string
 	if cnf.Contains(facultyLogLevelKey) {
 		facultyLogLevelStr = cnf.Get(facultyLogLevelKey)
diff --git a/htrace-htraced/go/src/org/apache/htrace/common/log_test.go b/htrace-htraced/go/src/org/apache/htrace/common/log_test.go
index b415ce2..f0b1cde 100644
--- a/htrace-htraced/go/src/org/apache/htrace/common/log_test.go
+++ b/htrace-htraced/go/src/org/apache/htrace/common/log_test.go
@@ -120,3 +120,51 @@
 	fooLg.Close()
 	barLg.Close()
 }
+
+func TestLogLevelEnabled(t *testing.T) {
+	tempDir, err := ioutil.TempDir(os.TempDir(), "TestLogLevelEnabled")
+	if err != nil {
+		panic(fmt.Sprintf("error creating tempdir: %s\n", err.Error()))
+	}
+	defer os.RemoveAll(tempDir)
+	// set log level to DEBUG for facility "foo"
+	logPath := tempDir + conf.PATH_SEP + "log"
+	lg := newLogger("foo", "log.level", "DEBUG",
+		"foo.log.level", "INFO",
+		"log.path", logPath)
+	if lg.TraceEnabled() {
+		t.Fatalf("foo logger has TraceEnabled")
+	}
+	if lg.DebugEnabled() {
+		t.Fatalf("foo logger have DebugEnabled")
+	}
+	if !lg.InfoEnabled() {
+		t.Fatalf("foo logger does not have InfoEnabled")
+	}
+	if !lg.WarnEnabled() {
+		t.Fatalf("foo logger does not have WarnEnabled")
+	}
+	if !lg.ErrorEnabled() {
+		t.Fatalf("foo logger does not have ErrorEnabled")
+	}
+	lg.Close()
+	lg = newLogger("foo", "log.level", "WARN",
+		"foo.log.level", "INFO",
+		"log.path", logPath)
+	if lg.TraceEnabled() {
+		t.Fatalf("foo logger has TraceEnabled")
+	}
+	if lg.DebugEnabled() {
+		t.Fatalf("foo logger has DebugEnabled")
+	}
+	if !lg.InfoEnabled() {
+		t.Fatalf("foo logger does not have InfoEnabled")
+	}
+	if !lg.WarnEnabled() {
+		t.Fatalf("foo logger does not have WarnEnabled")
+	}
+	if !lg.ErrorEnabled() {
+		t.Fatalf("foo logger does not have ErrorEnabled")
+	}
+	lg.Close()
+}