git » log » commit 4e4951f

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 c82a0ea146fbc2f816e4b19c10c214e31ab03e47

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, ☠.

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

diff --git a/log.go b/log.go
index 9cde2d1..10a7d9c 100644
--- a/log.go
+++ b/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/log_test.go b/log_test.go
index 06764d6..9c9763c 100644
--- a/log_test.go
+++ b/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) {