|
@@ -5,7 +5,6 @@ import (
|
|
|
"io"
|
|
|
"net/url"
|
|
|
"sort"
|
|
|
- "strings"
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
@@ -53,7 +52,8 @@ func WriteLogStream(ctx context.Context, w io.Writer, msgs <-chan *backend.LogMe
|
|
|
}
|
|
|
logLine := msg.Line
|
|
|
if config.Details {
|
|
|
- logLine = append([]byte(stringAttrs(msg.Attrs)+" "), logLine...)
|
|
|
+ logLine = append(attrsByteSlice(msg.Attrs), ' ')
|
|
|
+ logLine = append(logLine, msg.Line...)
|
|
|
}
|
|
|
if config.Timestamps {
|
|
|
// TODO(dperny) the format is defined in
|
|
@@ -71,24 +71,26 @@ func WriteLogStream(ctx context.Context, w io.Writer, msgs <-chan *backend.LogMe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type byKey []string
|
|
|
+type byKey []backend.LogAttr
|
|
|
|
|
|
-func (s byKey) Len() int { return len(s) }
|
|
|
-func (s byKey) Less(i, j int) bool {
|
|
|
- keyI := strings.Split(s[i], "=")
|
|
|
- keyJ := strings.Split(s[j], "=")
|
|
|
- return keyI[0] < keyJ[0]
|
|
|
-}
|
|
|
-func (s byKey) Swap(i, j int) {
|
|
|
- s[i], s[j] = s[j], s[i]
|
|
|
-}
|
|
|
+func (b byKey) Len() int { return len(b) }
|
|
|
+func (b byKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
|
|
+func (b byKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
|
|
|
|
|
-func stringAttrs(a backend.LogAttributes) string {
|
|
|
- var ss byKey
|
|
|
- for k, v := range a {
|
|
|
- k, v := url.QueryEscape(k), url.QueryEscape(v)
|
|
|
- ss = append(ss, k+"="+v)
|
|
|
+func attrsByteSlice(a []backend.LogAttr) []byte {
|
|
|
+ // Note this sorts "a" in-place. That is fine here - nothing else is
|
|
|
+ // going to use Attrs or care about the order.
|
|
|
+ sort.Sort(byKey(a))
|
|
|
+
|
|
|
+ var ret []byte
|
|
|
+ for i, pair := range a {
|
|
|
+ k, v := url.QueryEscape(pair.Key), url.QueryEscape(pair.Value)
|
|
|
+ ret = append(ret, []byte(k)...)
|
|
|
+ ret = append(ret, '=')
|
|
|
+ ret = append(ret, []byte(v)...)
|
|
|
+ if i != len(a)-1 {
|
|
|
+ ret = append(ret, ',')
|
|
|
+ }
|
|
|
}
|
|
|
- sort.Sort(ss)
|
|
|
- return strings.Join(ss, ",")
|
|
|
+ return ret
|
|
|
}
|