Documentation
¶
Overview ¶
Package text implements a text formatter which implements the Formatter.
Index ¶
- Constants
- type Color
- type Config
- type Formatter
- func (formatter *Formatter) Color(level iface.Level) Color
- func (formatter *Formatter) Coloring() bool
- func (formatter *Formatter) DisableColoring()
- func (formatter *Formatter) EnableColoring()
- func (formatter *Formatter) Format(record *iface.Record) []byte
- func (formatter *Formatter) Header() string
- func (formatter *Formatter) MapColors(colorMap map[iface.Level]Color)
- func (formatter *Formatter) MarkedColor() Color
- func (formatter *Formatter) MinBufSize() int
- func (formatter *Formatter) SetColor(level iface.Level, color Color)
- func (formatter *Formatter) SetHeader(header string)
- func (formatter *Formatter) SetMarkedColor(color Color)
- func (formatter *Formatter) SetMinBufSize(size int)
Constants ¶
const ( FullHeader = "{{time}} {{level}} {{file}}:{{line}} {{pkg}}.{{func}} " + "{{prefix}}[{{context}}] {{msg}}\n" CompactHeader = "{{time:time.us}} {{level}} {{file:1}}:{{line}} " + "{{pkg}}.{{func}} {{prefix}}[{{context}}] {{msg}}\n" SyslogHeader = "{{file:1}}:{{line}} {{pkg}}.{{func}} {{prefix}}" + "[{{context}}] {{msg}}\n" )
All predefined headers here.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.3.0
type Config struct { // Header is the format specifier of a text formatter. // It is used to specify which and how the fields of a Record to be formatted. // The pattern of a field specifier is {{<name>[:property][%fmtstr]}}. // e.g. {{level:char}}, {{line%05d}}, {{pkg:1}}, {{context:list%40s}} // All fields have support for the fmtstr. If the fmtstr is NOT the default // one of a field, it will be passed to fmt.Sprintf to format the field and // this affects the performance a little. // The supported properties vary with fields. // All supported fields are as the follows: // name | supported property | defaults | property examples // ----------+--------------------------+--------------+------------------------ // time | <date|time>[.ms|.us|.ns] | "date.us" %s | "date.ns", "time" // | layout that is supported | | time.RFC3339Nano // | by the time package | | "02 Jan 06 15:04 -0700" // level | <full|char> | "full" %s | "full", "char" // file | <lastSegs> | 0 %s | 0, 1, 2, ... // line | | %d | // pkg | <lastSegs> | 0 %s | 0, 1, 2, ... // func | <lastSegs> | 0 %s | 0, 1, 2, ... // prefix | | %s | // context | <pair|list> | "pair" %s | "pair", "list" // msg | | %s | // If Header is not specified, FullHeader is used. Header string // MinBufSize is the initial size of the internal buf of a formatter. // MinBufSize must NOT be negative. If it is not specified, 256 is used. MinBufSize int // ColorMap is used to remap the color of each level. // By default, the color of Trace, Debug and Info is Green, the color of Warn // is Yellow, the color of Error and Fatal is Red. The color of a marked log // is Magenta despite of its level. // The color of a level is left to be unchanged if it is not in the map. ColorMap map[iface.Level]Color // Coloring specifies whether colorization is enabled. Coloring bool }
A Config is used to configure a text formatter.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
A Formatter implements the interface iface.Formatter.
All methods of a Formatter are concurrency safe. A Formatter MUST be created with New.
func (*Formatter) Coloring ¶ added in v0.7.0
Coloring returns whether colorization is enabled in the Formatter.
func (*Formatter) DisableColoring ¶ added in v0.7.0
func (formatter *Formatter) DisableColoring()
DisableColoring disables colorization in the Formatter.
func (*Formatter) EnableColoring ¶ added in v0.7.0
func (formatter *Formatter) EnableColoring()
EnableColoring enables colorization in the Formatter.
func (*Formatter) MapColors ¶ added in v0.3.0
MapColors maps the color of levels in the Formatter according to the colorMap. The color of a level is left to be unchanged if it is not in the map.
func (*Formatter) MarkedColor ¶ added in v0.4.0
MarkedColor returns the color of a log that is marked.
func (*Formatter) MinBufSize ¶ added in v0.4.0
MinBufSize returns the min buf size of the Formatter.
func (*Formatter) SetHeader ¶
SetHeader sets the header of the Formatter. For details of all supported fields in a header, see the comment of Config.
func (*Formatter) SetMarkedColor ¶ added in v0.3.0
SetMarkedColor sets the color of a log that is marked.
func (*Formatter) SetMinBufSize ¶ added in v0.4.0
SetMinBufSize sets the min buf size of the Formatter. The size must NOT be negative. If the size is 0, 256 is used.