formatter

package
v0.0.0-...-e2451da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2015 License: MIT Imports: 5 Imported by: 8

Documentation

Overview

The formatter package is used to wrap an event with helper functions so it can be easily used in text templates.

Index

Constants

View Source
const (
	SIMPLE_FORMAT          = "{{.Message}} --{{range $k,$v := .Fields}} {{$k}}={{$.Quote $v}}{{end}}"
	CONSOLE_COLOR_FORMAT   = "" /* 174-byte string literal not displayed */
	CONSOLE_NOCOLOR_FORMAT = "" /* 155-byte string literal not displayed */
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	Event *event.Event
}

func EventFormatter

func EventFormatter(logEvent *event.Event) *Formatter

EventFormatter constructs a new Formatter containing the given event.

func (*Formatter) Color

func (formatter *Formatter) Color(text string) string

Color wraps the given text in ANSI color escapes appropriate to the event's level. Error and higher are red. Warning is yellow. Notice and lower are cyan.

func (*Formatter) Fields

func (formatter *Formatter) Fields() map[string]interface{}

Fields returns a map of the event's fields in single-level dot key notation. If the event's fields contain nested data, the nested data is flattened into a single level, with the previously nested levels added as keys prefixed with the parent's level, and a dot ('.').

For example:

map[string]interface{}{"foo": map[string]interface{}{"bar": "baz"}}

Will convert to `foo.bar=baz`

func (*Formatter) Level

func (formatter *Formatter) Level() string

Level converts the event's level into a string.

func (*Formatter) Message

func (formatter *Formatter) Message() string

Message returns the event's message.

func (*Formatter) Pad

func (formatter *Formatter) Pad(size int, text string) string

Pad pads the provided text to the specified length, while properly handling the color escape codes. Like the `%-10s` format, negative values mean pad on the right, where as positive values mean pad on the left.

func (*Formatter) Quote

func (formatter *Formatter) Quote(data interface{}) string

Quote converts the given data into a string, and adds quotes if necessary. Quotes are deemed necessary if the string contains whitespace, non-printable characters, or quotation marks.

func (*Formatter) Time

func (formatter *Formatter) Time(format string) string

Time converts the event's time into a string according to the given format. The format is the same as used by time.Format().

func (*Formatter) ToString

func (formatter *Formatter) ToString(data interface{}) string

ToString converts any arbitrary data into a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL