github.com/blend/go-sdk@v1.20220411.3/logger/write_helpers.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package logger 9 10 import ( 11 "fmt" 12 "sort" 13 "strings" 14 15 "github.com/blend/go-sdk/ansi" 16 ) 17 18 // FormatLabels formats the output of labels as a string. 19 // Field keys will be printed in alphabetic order. 20 func FormatLabels(tf TextFormatter, keyColor ansi.Color, labels Labels) string { 21 var keys []string 22 for key := range labels { 23 keys = append(keys, key) 24 } 25 sort.Strings(keys) 26 27 var values []string 28 for _, key := range keys { 29 values = append(values, fmt.Sprintf("%s=%s", tf.Colorize(key, keyColor), labels[key])) 30 } 31 return strings.Join(values, " ") 32 }