From 594f1ead6b3d3cd1bff081e48a8771524ad39b51 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sat, 10 Oct 2015 17:08:49 -0700 Subject: [PATCH] made it so the context is written out in alphabetical order. --- pretty_writing_router.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/pretty_writing_router.go b/pretty_writing_router.go index 0b43813..296f4db 100644 --- a/pretty_writing_router.go +++ b/pretty_writing_router.go @@ -4,6 +4,7 @@ package flog import ( "fmt" "io" + "sort" "time" ) @@ -58,17 +59,32 @@ func (router *PrettyWritingRouter) Route(message string, context map[string]inte } str = fmt.Sprintf("%s%s%s%s\t(%s%v%s)", str, STYLE_MESSAGE, message, STYLE_RESET, STYLE_TIMESTAMP, time.Now(), STYLE_RESET) - for key, value := range context { + +//@TODO: This is a potential heavy operation. Is there a better way +// to get the ultimate result this is trying to archive? +// + sortedKeys := make([]string, len(context)) + i := 0 + for key, _ := range context { + sortedKeys[i] = key + i++ + } + sort.Strings(sortedKeys) + + for _, key := range sortedKeys { + + value := context[key] + style := STYLE_DEFAULT switch key { - case "panic": + case "panic", "panics": style = STYLE_PANIC - case "error": + case "error", "errors": style = STYLE_ERROR - case "warning": + case "warning", "warnings": style = STYLE_WARNING - case "notice": + case "notice", "notices": style = STYLE_NOTICE }