2017-08-06 02:59:04 +00:00
|
|
|
package zerolog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2018-11-05 10:15:13 +00:00
|
|
|
"os"
|
2020-12-28 21:38:24 +00:00
|
|
|
"path/filepath"
|
2017-08-06 02:59:04 +00:00
|
|
|
"sort"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2018-05-17 23:09:39 +00:00
|
|
|
"time"
|
2021-12-19 22:50:53 +00:00
|
|
|
|
|
|
|
"github.com/mattn/go-colorable"
|
2017-08-06 02:59:04 +00:00
|
|
|
)
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
const (
|
|
|
|
colorBlack = iota + 30
|
|
|
|
colorRed
|
|
|
|
colorGreen
|
|
|
|
colorYellow
|
|
|
|
colorBlue
|
|
|
|
colorMagenta
|
|
|
|
colorCyan
|
|
|
|
colorWhite
|
2019-02-07 15:45:02 +00:00
|
|
|
|
|
|
|
colorBold = 1
|
|
|
|
colorDarkGray = 90
|
2018-11-05 10:15:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
consoleBufPool = sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return bytes.NewBuffer(make([]byte, 0, 100))
|
|
|
|
},
|
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
)
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
const (
|
2018-11-05 10:15:13 +00:00
|
|
|
consoleDefaultTimeFormat = time.Kitchen
|
|
|
|
)
|
|
|
|
|
|
|
|
// Formatter transforms the input into a formatted string.
|
|
|
|
type Formatter func(interface{}) string
|
2018-07-25 17:05:55 +00:00
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
// ConsoleWriter parses the JSON input and writes it in an
|
|
|
|
// (optionally) colorized, human-friendly format to Out.
|
2017-08-06 02:59:04 +00:00
|
|
|
type ConsoleWriter struct {
|
2018-11-05 10:15:13 +00:00
|
|
|
// Out is the output destination.
|
|
|
|
Out io.Writer
|
|
|
|
|
|
|
|
// NoColor disables the colorized output.
|
2017-08-06 02:59:04 +00:00
|
|
|
NoColor bool
|
2018-11-05 10:15:13 +00:00
|
|
|
|
|
|
|
// TimeFormat specifies the format for timestamp in output.
|
|
|
|
TimeFormat string
|
|
|
|
|
|
|
|
// PartsOrder defines the order of parts in output.
|
|
|
|
PartsOrder []string
|
|
|
|
|
2020-11-29 09:13:56 +00:00
|
|
|
// PartsExclude defines parts to not display in output.
|
|
|
|
PartsExclude []string
|
|
|
|
|
2022-02-27 17:33:36 +00:00
|
|
|
// FieldsExclude defines contextual fields to not display in output.
|
|
|
|
FieldsExclude []string
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
FormatTimestamp Formatter
|
|
|
|
FormatLevel Formatter
|
|
|
|
FormatCaller Formatter
|
|
|
|
FormatMessage Formatter
|
|
|
|
FormatFieldName Formatter
|
|
|
|
FormatFieldValue Formatter
|
|
|
|
FormatErrFieldName Formatter
|
|
|
|
FormatErrFieldValue Formatter
|
2017-08-06 02:59:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
// NewConsoleWriter creates and initializes a new ConsoleWriter.
|
|
|
|
func NewConsoleWriter(options ...func(w *ConsoleWriter)) ConsoleWriter {
|
|
|
|
w := ConsoleWriter{
|
|
|
|
Out: os.Stdout,
|
|
|
|
TimeFormat: consoleDefaultTimeFormat,
|
2018-11-07 17:39:38 +00:00
|
|
|
PartsOrder: consoleDefaultPartsOrder(),
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range options {
|
|
|
|
opt(&w)
|
|
|
|
}
|
|
|
|
|
2021-12-19 22:50:53 +00:00
|
|
|
// Fix color on Windows
|
|
|
|
if w.Out == os.Stdout || w.Out == os.Stderr {
|
|
|
|
w.Out = colorable.NewColorable(w.Out.(*os.File))
|
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write transforms the JSON input with formatters and appends to w.Out.
|
2017-08-06 02:59:04 +00:00
|
|
|
func (w ConsoleWriter) Write(p []byte) (n int, err error) {
|
2021-12-19 22:50:53 +00:00
|
|
|
// Fix color on Windows
|
|
|
|
if w.Out == os.Stdout || w.Out == os.Stderr {
|
|
|
|
w.Out = colorable.NewColorable(w.Out.(*os.File))
|
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
if w.PartsOrder == nil {
|
2018-11-07 17:39:38 +00:00
|
|
|
w.PartsOrder = consoleDefaultPartsOrder()
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var buf = consoleBufPool.Get().(*bytes.Buffer)
|
2018-12-05 07:46:12 +00:00
|
|
|
defer func() {
|
|
|
|
buf.Reset()
|
|
|
|
consoleBufPool.Put(buf)
|
|
|
|
}()
|
2018-11-05 10:15:13 +00:00
|
|
|
|
|
|
|
var evt map[string]interface{}
|
2018-03-28 18:49:41 +00:00
|
|
|
p = decodeIfBinaryToBytes(p)
|
2018-04-19 20:12:29 +00:00
|
|
|
d := json.NewDecoder(bytes.NewReader(p))
|
|
|
|
d.UseNumber()
|
2018-11-05 10:15:13 +00:00
|
|
|
err = d.Decode(&evt)
|
2017-08-06 02:59:04 +00:00
|
|
|
if err != nil {
|
2018-11-05 10:15:13 +00:00
|
|
|
return n, fmt.Errorf("cannot decode event: %s", err)
|
2017-08-06 02:59:04 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
|
|
|
for _, p := range w.PartsOrder {
|
|
|
|
w.writePart(buf, evt, p)
|
2022-06-28 23:36:09 +00:00
|
|
|
delete(evt, p)
|
2017-08-06 02:59:04 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
|
|
|
w.writeFields(evt, buf)
|
|
|
|
|
2018-12-05 07:46:12 +00:00
|
|
|
err = buf.WriteByte('\n')
|
|
|
|
if err != nil {
|
|
|
|
return n, err
|
|
|
|
}
|
|
|
|
_, err = buf.WriteTo(w.Out)
|
|
|
|
return len(p), err
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// writeFields appends formatted key-value pairs to buf.
|
|
|
|
func (w ConsoleWriter) writeFields(evt map[string]interface{}, buf *bytes.Buffer) {
|
|
|
|
var fields = make([]string, 0, len(evt))
|
|
|
|
for field := range evt {
|
2022-02-27 17:33:36 +00:00
|
|
|
var isExcluded bool
|
|
|
|
for _, excluded := range w.FieldsExclude {
|
|
|
|
if field == excluded {
|
|
|
|
isExcluded = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isExcluded {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-08-06 02:59:04 +00:00
|
|
|
switch field {
|
2018-11-05 10:15:13 +00:00
|
|
|
case LevelFieldName, TimestampFieldName, MessageFieldName, CallerFieldName:
|
2017-08-06 02:59:04 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
fields = append(fields, field)
|
|
|
|
}
|
|
|
|
sort.Strings(fields)
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2022-02-19 15:39:18 +00:00
|
|
|
// Write space only if something has already been written to the buffer, and if there are fields.
|
|
|
|
if buf.Len() > 0 && len(fields) > 0 {
|
2018-11-05 10:15:13 +00:00
|
|
|
buf.WriteByte(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the "error" field to the front
|
|
|
|
ei := sort.Search(len(fields), func(i int) bool { return fields[i] >= ErrorFieldName })
|
|
|
|
if ei < len(fields) && fields[ei] == ErrorFieldName {
|
|
|
|
fields[ei] = ""
|
|
|
|
fields = append([]string{ErrorFieldName}, fields...)
|
|
|
|
var xfields = make([]string, 0, len(fields))
|
|
|
|
for _, field := range fields {
|
|
|
|
if field == "" { // Skip empty fields
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
xfields = append(xfields, field)
|
|
|
|
}
|
|
|
|
fields = xfields
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, field := range fields {
|
|
|
|
var fn Formatter
|
|
|
|
var fv Formatter
|
|
|
|
|
|
|
|
if field == ErrorFieldName {
|
|
|
|
if w.FormatErrFieldName == nil {
|
2018-12-07 17:59:01 +00:00
|
|
|
fn = consoleDefaultFormatErrFieldName(w.NoColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
} else {
|
|
|
|
fn = w.FormatErrFieldName
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.FormatErrFieldValue == nil {
|
2018-12-07 17:59:01 +00:00
|
|
|
fv = consoleDefaultFormatErrFieldValue(w.NoColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
} else {
|
|
|
|
fv = w.FormatErrFieldValue
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if w.FormatFieldName == nil {
|
2018-12-07 17:59:01 +00:00
|
|
|
fn = consoleDefaultFormatFieldName(w.NoColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
} else {
|
|
|
|
fn = w.FormatFieldName
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.FormatFieldValue == nil {
|
|
|
|
fv = consoleDefaultFormatFieldValue
|
|
|
|
} else {
|
|
|
|
fv = w.FormatFieldValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf.WriteString(fn(field))
|
|
|
|
|
|
|
|
switch fValue := evt[field].(type) {
|
2017-08-06 02:59:04 +00:00
|
|
|
case string:
|
2018-11-05 10:15:13 +00:00
|
|
|
if needsQuote(fValue) {
|
|
|
|
buf.WriteString(fv(strconv.Quote(fValue)))
|
2017-08-06 02:59:04 +00:00
|
|
|
} else {
|
2018-11-05 10:15:13 +00:00
|
|
|
buf.WriteString(fv(fValue))
|
2017-08-06 02:59:04 +00:00
|
|
|
}
|
2018-04-19 20:12:29 +00:00
|
|
|
case json.Number:
|
2018-11-05 10:15:13 +00:00
|
|
|
buf.WriteString(fv(fValue))
|
2018-02-13 08:20:42 +00:00
|
|
|
default:
|
2022-07-16 20:03:29 +00:00
|
|
|
b, err := InterfaceMarshalFunc(fValue)
|
2018-02-13 08:20:42 +00:00
|
|
|
if err != nil {
|
2018-11-05 10:15:13 +00:00
|
|
|
fmt.Fprintf(buf, colorize("[error: %v]", colorRed, w.NoColor), err)
|
2018-02-13 08:20:42 +00:00
|
|
|
} else {
|
2018-11-05 10:15:13 +00:00
|
|
|
fmt.Fprint(buf, fv(b))
|
2018-02-13 08:20:42 +00:00
|
|
|
}
|
2017-08-06 02:59:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
if i < len(fields)-1 { // Skip space for last field
|
|
|
|
buf.WriteByte(' ')
|
|
|
|
}
|
2018-05-17 23:09:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
// writePart appends a formatted part to buf.
|
|
|
|
func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, p string) {
|
|
|
|
var f Formatter
|
2017-08-06 02:59:04 +00:00
|
|
|
|
2020-11-29 09:13:56 +00:00
|
|
|
if w.PartsExclude != nil && len(w.PartsExclude) > 0 {
|
|
|
|
for _, exclude := range w.PartsExclude {
|
|
|
|
if exclude == p {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
switch p {
|
|
|
|
case LevelFieldName:
|
|
|
|
if w.FormatLevel == nil {
|
2018-12-07 17:59:01 +00:00
|
|
|
f = consoleDefaultFormatLevel(w.NoColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
} else {
|
|
|
|
f = w.FormatLevel
|
|
|
|
}
|
|
|
|
case TimestampFieldName:
|
|
|
|
if w.FormatTimestamp == nil {
|
2018-12-07 17:59:01 +00:00
|
|
|
f = consoleDefaultFormatTimestamp(w.TimeFormat, w.NoColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
} else {
|
|
|
|
f = w.FormatTimestamp
|
|
|
|
}
|
|
|
|
case MessageFieldName:
|
|
|
|
if w.FormatMessage == nil {
|
|
|
|
f = consoleDefaultFormatMessage
|
|
|
|
} else {
|
|
|
|
f = w.FormatMessage
|
|
|
|
}
|
|
|
|
case CallerFieldName:
|
|
|
|
if w.FormatCaller == nil {
|
2018-12-07 17:59:01 +00:00
|
|
|
f = consoleDefaultFormatCaller(w.NoColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
} else {
|
|
|
|
f = w.FormatCaller
|
|
|
|
}
|
2017-08-06 02:59:04 +00:00
|
|
|
default:
|
2018-11-05 10:15:13 +00:00
|
|
|
if w.FormatFieldValue == nil {
|
|
|
|
f = consoleDefaultFormatFieldValue
|
|
|
|
} else {
|
|
|
|
f = w.FormatFieldValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var s = f(evt[p])
|
|
|
|
|
|
|
|
if len(s) > 0 {
|
2022-02-19 15:39:18 +00:00
|
|
|
if buf.Len() > 0 {
|
|
|
|
buf.WriteByte(' ') // Write space only if not the first part
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2022-02-19 15:39:18 +00:00
|
|
|
buf.WriteString(s)
|
2017-08-06 02:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 10:15:13 +00:00
|
|
|
// needsQuote returns true when the string s should be quoted in output.
|
2017-08-06 02:59:04 +00:00
|
|
|
func needsQuote(s string) bool {
|
|
|
|
for i := range s {
|
2017-08-06 03:45:41 +00:00
|
|
|
if s[i] < 0x20 || s[i] > 0x7e || s[i] == ' ' || s[i] == '\\' || s[i] == '"' {
|
2017-08-06 02:59:04 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
|
|
|
// colorize returns the string s wrapped in ANSI code c, unless disabled is true.
|
|
|
|
func colorize(s interface{}, c int, disabled bool) string {
|
|
|
|
if disabled {
|
|
|
|
return fmt.Sprintf("%s", s)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("\x1b[%dm%v\x1b[0m", c, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----- DEFAULT FORMATTERS ---------------------------------------------------
|
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultPartsOrder() []string {
|
|
|
|
return []string{
|
|
|
|
TimestampFieldName,
|
|
|
|
LevelFieldName,
|
|
|
|
CallerFieldName,
|
|
|
|
MessageFieldName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func consoleDefaultFormatTimestamp(timeFormat string, noColor bool) Formatter {
|
|
|
|
if timeFormat == "" {
|
|
|
|
timeFormat = consoleDefaultTimeFormat
|
|
|
|
}
|
|
|
|
return func(i interface{}) string {
|
2018-11-05 10:15:13 +00:00
|
|
|
t := "<nil>"
|
2018-11-12 08:50:17 +00:00
|
|
|
switch tt := i.(type) {
|
|
|
|
case string:
|
2018-12-07 17:59:01 +00:00
|
|
|
ts, err := time.Parse(TimeFieldFormat, tt)
|
2018-11-05 10:15:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t = tt
|
|
|
|
} else {
|
2022-07-16 20:02:45 +00:00
|
|
|
t = ts.Local().Format(timeFormat)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2018-11-12 08:50:17 +00:00
|
|
|
case json.Number:
|
2019-04-25 19:01:27 +00:00
|
|
|
i, err := tt.Int64()
|
|
|
|
if err != nil {
|
|
|
|
t = tt.String()
|
|
|
|
} else {
|
2019-04-25 19:44:49 +00:00
|
|
|
var sec, nsec int64 = i, 0
|
2019-12-20 17:34:21 +00:00
|
|
|
switch TimeFieldFormat {
|
|
|
|
case TimeFormatUnixMs:
|
2019-04-25 19:44:49 +00:00
|
|
|
nsec = int64(time.Duration(i) * time.Millisecond)
|
|
|
|
sec = 0
|
2019-12-20 17:34:21 +00:00
|
|
|
case TimeFormatUnixMicro:
|
|
|
|
nsec = int64(time.Duration(i) * time.Microsecond)
|
|
|
|
sec = 0
|
2019-04-25 19:44:49 +00:00
|
|
|
}
|
2022-07-16 20:02:45 +00:00
|
|
|
ts := time.Unix(sec, nsec)
|
2019-04-25 19:01:27 +00:00
|
|
|
t = ts.Format(timeFormat)
|
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2019-02-07 15:45:02 +00:00
|
|
|
return colorize(t, colorDarkGray, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatLevel(noColor bool) Formatter {
|
|
|
|
return func(i interface{}) string {
|
2018-11-05 10:15:13 +00:00
|
|
|
var l string
|
|
|
|
if ll, ok := i.(string); ok {
|
|
|
|
switch ll {
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelTraceValue:
|
2019-11-04 19:39:22 +00:00
|
|
|
l = colorize("TRC", colorMagenta, noColor)
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelDebugValue:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize("DBG", colorYellow, noColor)
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelInfoValue:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize("INF", colorGreen, noColor)
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelWarnValue:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize("WRN", colorRed, noColor)
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelErrorValue:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize(colorize("ERR", colorRed, noColor), colorBold, noColor)
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelFatalValue:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize(colorize("FTL", colorRed, noColor), colorBold, noColor)
|
2021-07-15 20:04:15 +00:00
|
|
|
case LevelPanicValue:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize(colorize("PNC", colorRed, noColor), colorBold, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
default:
|
2018-12-07 17:59:01 +00:00
|
|
|
l = colorize("???", colorBold, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-04-25 19:12:24 +00:00
|
|
|
if i == nil {
|
|
|
|
l = colorize("???", colorBold, noColor)
|
|
|
|
} else {
|
|
|
|
l = strings.ToUpper(fmt.Sprintf("%s", i))[0:3]
|
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatCaller(noColor bool) Formatter {
|
|
|
|
return func(i interface{}) string {
|
2018-11-05 10:15:13 +00:00
|
|
|
var c string
|
|
|
|
if cc, ok := i.(string); ok {
|
|
|
|
c = cc
|
|
|
|
}
|
|
|
|
if len(c) > 0 {
|
2020-12-28 21:38:24 +00:00
|
|
|
if cwd, err := os.Getwd(); err == nil {
|
|
|
|
if rel, err := filepath.Rel(cwd, c); err == nil {
|
|
|
|
c = rel
|
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2019-02-07 15:45:02 +00:00
|
|
|
c = colorize(c, colorBold, noColor) + colorize(" >", colorCyan, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
|
|
|
return c
|
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatMessage(i interface{}) string {
|
2019-04-25 19:01:27 +00:00
|
|
|
if i == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
return fmt.Sprintf("%s", i)
|
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatFieldName(noColor bool) Formatter {
|
|
|
|
return func(i interface{}) string {
|
2019-02-07 15:45:02 +00:00
|
|
|
return colorize(fmt.Sprintf("%s=", i), colorCyan, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatFieldValue(i interface{}) string {
|
|
|
|
return fmt.Sprintf("%s", i)
|
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatErrFieldName(noColor bool) Formatter {
|
|
|
|
return func(i interface{}) string {
|
2021-11-09 11:34:43 +00:00
|
|
|
return colorize(fmt.Sprintf("%s=", i), colorCyan, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
}
|
2018-11-05 10:15:13 +00:00
|
|
|
|
2018-12-07 17:59:01 +00:00
|
|
|
func consoleDefaultFormatErrFieldValue(noColor bool) Formatter {
|
|
|
|
return func(i interface{}) string {
|
|
|
|
return colorize(fmt.Sprintf("%s", i), colorRed, noColor)
|
2018-11-05 10:15:13 +00:00
|
|
|
}
|
2018-12-07 17:59:01 +00:00
|
|
|
}
|