git » chasquid » commit 6479138

log: Add a symbol for Fatal log entries

author Alberto Bertogli
2016-11-24 10:18:04 UTC
committer Alberto Bertogli
2016-11-24 10:18:04 UTC
parent 75cc038e686eb34015a9833df922ff3e2636476e

log: Add a symbol for Fatal log entries

Currently there is no symbol for Fatal-level log entries, so they appear
with "-2", which is distracting.

This patch makes the Fatal log entries have their own symbol, ☠.

internal/log/log.go +2 -0
internal/log/log_test.go +5 -0

diff --git a/internal/log/log.go b/internal/log/log.go
index 9cde2d1..10a7d9c 100644
--- a/internal/log/log.go
+++ b/internal/log/log.go
@@ -44,12 +44,14 @@ var (
 type Level int
 
 const (
+	Fatal = Level(-2)
 	Error = Level(-1)
 	Info  = Level(0)
 	Debug = Level(1)
 )
 
 var levelToLetter = map[Level]string{
+	Fatal: "☠",
 	Error: "E",
 	Info:  "_",
 	Debug: ".",
diff --git a/internal/log/log_test.go b/internal/log/log_test.go
index 06764d6..9c9763c 100644
--- a/internal/log/log_test.go
+++ b/internal/log/log_test.go
@@ -81,6 +81,11 @@ func testLogger(t *testing.T, fname string, l *Logger) {
 	checkContentsMatch(t, "log", fname,
 		`^_ log_test.go:....   log info 1\n`)
 
+	os.Truncate(fname, 0)
+	l.Level = Info
+	l.Log(Fatal, 0, "log fatal %d", 1)
+	checkContentsMatch(t, "log", fname,
+		`^☠ log_test.go:....   log fatal 1\n`)
 }
 
 func TestBasic(t *testing.T) {