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
- type Formatter
- func (formatter *Formatter) Color(text string) string
- func (formatter *Formatter) Fields() map[string]interface{}
- func (formatter *Formatter) Level() string
- func (formatter *Formatter) Message() string
- func (formatter *Formatter) Pad(size int, text string) string
- func (formatter *Formatter) Quote(data interface{}) string
- func (formatter *Formatter) Time(format string) string
- func (formatter *Formatter) ToString(data interface{}) string
Constants ¶
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 ¶
func EventFormatter ¶
EventFormatter constructs a new Formatter containing the given event.
func (*Formatter) Color ¶
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 ¶
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) Pad ¶
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 ¶
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.