// Formatting function used to implement the %json:message% code.
322027
func ioOutputFormatJsonMessage(ld *LineData, b *bytes.Buffer) error {
	msg, err := json.Marshal(ld.Message)
	if err != nil {
		return err
	}

	_, err = b.WriteString(string(msg))
	return err
}
930608
func simpleMessageFormatter(entry *JournalEntry) (string, error) {
	msg, ok := entry.Fields["MESSAGE"]
	if !ok {
		return "", fmt.Errorf("no MESSAGE field present in journal entry")
	}

	usec := entry.RealtimeTimestamp
	timestamp := time.Unix(0, int64(usec)*int64(time.Microsecond))

	return fmt.Sprintf("%s %s\n", timestamp, msg), nil
}
152737
func (format *Identifier) ApplyFormatter(msg *core.Message) error {
	format.SetAppliedContent(msg, format.hash(msg))
	return nil
}
37042
func (format *MetadataCopy) ApplyFormatter(msg *core.Message) error {

	if len(format.metaDataKeys) > 0 {
		// DEPRECATED
		// This codepath will be removed in 0.6
		meta := msg.GetMetadata()
		data := format.GetAppliedContent(msg)

		for _, key := range format.metaDataKeys {
			bufferCopy := make([]byte, len(data))
			copy(bufferCopy, data)
			meta.SetValue(key, bufferCopy)
		}
		return nil
	}

	getSourceData := core.GetAppliedContentGetFunction(format.key)
	srcData := getSourceData(msg)

	cloneSrcData := make([]byte, len(srcData))
	copy(cloneSrcData, srcData)

	switch format.mode {
	case metadataCopyModeReplace:
		format.SetAppliedContent(msg, cloneSrcData)

	case metadataCopyModePrepend:
		dstData := format.GetAppliedContent(msg)
		if len(format.separator) != 0 {
			cloneSrcData = append(cloneSrcData, format.separator...)
		}
		format.SetAppliedContent(msg, append(cloneSrcData, dstData...))

	case metadataCopyModeAppend:
		dstData := format.GetAppliedContent(msg)
		if len(format.separator) != 0 {
			dstData = append(dstData, format.separator...)
		}
		format.SetAppliedContent(msg, append(dstData, cloneSrcData...))
	}

	return nil
}
1154124
func (e Error) Format(a ...interface{}) Error {
	e.Message = fmt.Sprintf(e.Message, a...)
	return e
}
1221104
func (format *Envelope) ApplyFormatter(msg *core.Message) error {
	prefixLen := len(format.prefix)
	postfixLen := len(format.postfix)
	content := format.GetAppliedContent(msg)
	offset := 0

	payload := make([]byte, prefixLen+len(content)+postfixLen)

	if prefixLen > 0 {
		offset = copy(payload, format.prefix)
	}

	offset += copy(payload[offset:], content)

	if postfixLen > 0 {
		copy(payload[offset:], format.postfix)
	}

	format.SetAppliedContent(msg, payload)
	return nil
}
452472
func Format(t string) (ReadWriteFormatter, error) {
	formatter, ok := formatters[t]
	if !ok {
		return &JSONFormatter{}, ErrNotSuppoted
	}

	return formatter, nil
}
1333577
func message(format string, args ...interface{}) {
	fmt.Printf("SIS: %v\n", fmt.Sprintf(format, args...))
}
621691
func (hd *HappyDevFormatter) Format(writer io.Writer, level int, msg string, args []interface{}) {
	buf := pool.Get()
	defer pool.Put(buf)

	if len(args) == 1 {
		args = append(args, 0)
		copy(args[1:], args[0:])
		args[0] = singleArgKey
	}

	// warn about reserved, bad and complex keys
	for i := 0; i < len(args); i += 2 {
		isReserved, err := isReservedKey(args[i])
		if err != nil {
			InternalLog.Error("Key is not a string.", "err", fmt.Errorf("args[%d]=%v", i, args[i]))
		} else if isReserved {
			InternalLog.Fatal("Key conflicts with reserved key. Avoiding using single rune keys.", "key", args[i].(string))
		} else {
			// Ensure keys are simple strings. The JSONFormatter doesn't escape
			// keys as a performance tradeoff. This panics if the JSON key
			// value has a different value than a simple quoted string.
			key := args[i].(string)
			b, err := json.Marshal(key)
			if err != nil {
				panic("Key is invalid. " + err.Error())
			}
			if string(b) != `"`+key+`"` {
				panic("Key is complex. Use simpler key for: " + fmt.Sprintf("%q", key))
			}
		}
	}

	// use the production JSON formatter to format the log first. This
	// ensures JSON will marshal/unmarshal correctly in production.
	entry := hd.jsonFormatter.LogEntry(level, msg, args)

	// reset the column tracker used for fancy formatting
	hd.col = 0

	// timestamp
	buf.WriteString(theme.Misc)
	hd.writeString(buf, entry[KeyMap.Time].(string))
	if !disableColors {
		buf.WriteString(ansi.Reset)
	}

	// emphasize warnings and errors
	message, context, color := hd.getLevelContext(level, entry)
	if message == "" {
		message = entry[KeyMap.Message].(string)
	}

	// DBG, INF ...
	hd.set(buf, "", entry[KeyMap.Level].(string), color)
	// logger name
	hd.set(buf, "", entry[KeyMap.Name], theme.Misc)
	// message from user
	hd.set(buf, "", message, theme.Message)

	// Preserve key order in the sequencethey were added by developer.This
	// makes it easier for developers to follow the log.
	order := []string{}
	lenArgs := len(args)
	for i := 0; i < len(args); i += 2 {
		if i+1 >= lenArgs {
			continue
		}
		if key, ok := args[i].(string); ok {
			order = append(order, key)
		} else {
			order = append(order, badKeyAtIndex(i))
		}
	}

	for _, key := range order {
		// skip reserved keys which were already added to buffer above
		isReserved, err := isReservedKey(key)
		if err != nil {
			panic("key is invalid. Should never get here. " + err.Error())
		} else if isReserved {
			continue
		}
		hd.set(buf, key, entry[key], theme.Value)
	}

	addLF := true
	hasCallStack := entry[KeyMap.CallStack] != nil
	// WRN,ERR file, line number context

	if context != "" {
		// warnings and traces are single line, space can be optimized
		if level == LevelTrace || (level == LevelWarn && !hasCallStack) {
			// gets rid of "in "
			idx := strings.IndexRune(context, 'n')
			hd.set(buf, "in", context[idx+2:], color)
		} else {
			buf.WriteRune('\n')
			if !disableColors {
				buf.WriteString(color)
			}
			addLF = context[len(context)-1:len(context)] != "\n"
			buf.WriteString(context)
			if !disableColors {
				buf.WriteString(ansi.Reset)
			}
		}
	} else if hasCallStack {
		hd.set(buf, "", entry[KeyMap.CallStack], color)
	}
	if addLF {
		buf.WriteRune('\n')
	}
	buf.WriteTo(writer)
}
126739
func message(canvas *svg.SVG, x, y, w, h, l int, bcolor, scolor string) {
	et := h / 3
	w2 := w / 2
	px := w / 8
	py := h / 8
	e1x := []int{x, x, x + w, x + w, x + w2, x}
	e1y := []int{y + et, y + h, y + h, y + et, y + (et * 2), y + et}
	e2x := []int{x, x + w2, x + w, x + w2, x}
	e2y := []int{y + et, y, y + et, y + (et * 2), y + et}

	canvas.Polygon(e2x, e2y, "fill:"+bcolor)
	canvas.Polygon(e1x, e1y, "fill:"+scolor)
	canvas.Roundrect(x+px, y+py, w-(px*2), h-py, l, l, "fill:"+scolor)
	canvas.Line(x, y+et, x+w2, y+(et*2), "stroke-width:1;stroke:"+bcolor)
	canvas.Line(x+w, y+et, x+w2, y+(et*2), "stroke-width:1;stroke:"+bcolor)
}
704837
func (s updateMessage) JSON() string {
	updateJSONBytes, e := json.MarshalIndent(s, "", " ")
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(updateJSONBytes)
}
820923
func (d *DiffResult) JSONFormat() (string, error) {
	if !d.Diff.Modified() {
		return "", nil
	}
	jsonFmt := formatter.NewDeltaFormatter()
	return jsonFmt.Format(d.Diff)
}
860864
func (format *Timestamp) ApplyFormatter(msg *core.Message) error {
	timestampStr := msg.GetCreationTime().Format(format.timestampFormat)
	content := format.GetAppliedContent(msg)

	dataSize := len(timestampStr) + len(content)
	payload := make([]byte, dataSize)

	offset := copy(payload, []byte(timestampStr))
	copy(payload[offset:], content)

	format.SetAppliedContent(msg, payload)
	return nil
}
1332750
func (formatterModulator *FormatterModulator) ApplyFormatter(msg *Message) error {
	if formatterModulator.CanBeApplied(msg) {
		return formatterModulator.Formatter.ApplyFormatter(msg)
	}
	return nil
}
1232895
func (l Log) Format() (string, error) {
	res, err := json.Marshal(l)
	if err == nil {
		return string(res), nil
	}
	return "", err
}
1170581
func NewFormattedMessage(p level.Priority, base string, args ...interface{}) Composer {
	m := &formatMessenger{
		base: base,
		args: args,
	}
	_ = m.SetPriority(p)

	return m
}
1347188
func (f *PoliteJSONFormatter) Format(calldepth int, r *logging.Record, w io.Writer) error {
	entry := make(map[string]interface{})
	entry["id"] = r.Id
	entry["level"] = r.Level
	entry["time"] = r.Time
	entry["module"] = r.Module
	entry["message"] = r.Message()
	err := json.NewEncoder(w).Encode(entry)
	if err != nil {
		return err
	}

	w.Write([]byte{'\n'})
	return nil
}