func (w ConsoleWriter) Write(p []byte) (n int, err error) {
	if w.PartsOrder == nil {
		w.PartsOrder = consoleDefaultPartsOrder()
	}
	if w.TimeFormat == "" && consoleTimeFormat != consoleDefaultTimeFormat {
		consoleTimeFormat = consoleDefaultTimeFormat
	}
	if w.TimeFormat != "" && consoleTimeFormat != w.TimeFormat {
		consoleTimeFormat = w.TimeFormat
	}
	if w.NoColor == false && consoleNoColor != false {
		consoleNoColor = false
	}
	if w.NoColor == true && consoleNoColor != w.NoColor {
		consoleNoColor = w.NoColor
	}
	var buf = consoleBufPool.Get().(*bytes.Buffer)
	defer consoleBufPool.Put(buf)
	var evt map[string]interface{}
	p = decodeIfBinaryToBytes(p)
	d := json.NewDecoder(bytes.NewReader(p))
	d.UseNumber()
	err = d.Decode(&evt)
	if err != nil {
		return n, fmt.Errorf("cannot decode event: %s", err)
	}
	for _, p := range w.PartsOrder {
		w.writePart(buf, evt, p)
	}
	w.writeFields(evt, buf)
	buf.WriteByte('\n')
	buf.WriteTo(w.Out)
	return len(p), nil
}
Write transforms the JSON input with formatters and appends to w.Out.
package zerolog
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
	"time"
)
const (
	colorBold = iota + 1
	colorFaint
)
const (
	colorBlack = iota + 30
	colorRed
	colorGreen
	colorYellow
	colorBlue
	colorMagenta
	colorCyan
	colorWhite
)
var (
	consoleBufPool = sync.Pool{
		New: func() interface{} {
			return bytes.NewBuffer(make([]byte, 0, 100))
		},
	}
	consoleDefaultTimeFormat = time.Kitchen
	consoleDefaultFormatter  = func(i interface{}) string { return fmt.Sprintf("%s", i) }
	consoleDefaultPartsOrder = func() []string {
		return []string{
			TimestampFieldName,
			LevelFieldName,
			CallerFieldName,
			MessageFieldName,
		}
	}
	consoleNoColor    = false
	consoleTimeFormat = consoleDefaultTimeFormat
)
type Formatter func(interface{}) string
type ConsoleWriter struct {
	Out io.Writer
	NoColor bool
	TimeFormat string
	PartsOrder []string
	FormatTimestamp     Formatter
	FormatLevel         Formatter
	FormatCaller        Formatter
	FormatMessage       Formatter
	FormatFieldName     Formatter
	FormatFieldValue    Formatter
	FormatErrFieldName  Formatter
	FormatErrFieldValue Formatter
}
func NewConsoleWriter(options ...func(w *ConsoleWriter)) ConsoleWriter {
	w := ConsoleWriter{
		Out:        os.Stdout,
		TimeFormat: consoleDefaultTimeFormat,
		PartsOrder: consoleDefaultPartsOrder(),
	}
	for _, opt := range options {
		opt(&w)
	}
	return w
}