Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
func ColorFormatter ¶
ColorFormatter returns a formatter that will map ANSI color codes into the output based on matching tags in the tag map. For instance:
colors := map[string]colors.Color{ "hl": colors.BrightWhite, "em": colors.Cyan, "warn": colors.Yellow, "fail": colors.Red, "success": colors.Green, } formatter := ColorFormatter(colors)
func ContextFormatter ¶
func ContextFormatter() Formatter
ContextColorFormatter will format text based on some simple context tags. The colors are looked up from ContextColors
<hl>highlight</hl> - colors.BrightWhite <em>emphasis</em> - colors.Cyan <warn></warn> - colors.Yellow <fail></fail> - colors.Red
<success></success> - colors.Green
type Logger ¶
type Logger interface { Log(v ...interface{}) Logf(format string, v ...interface{}) }
func ColorLogger ¶
Example ¶
package main import ( "os" "github.com/abates/formatter" ) func main() { logger := formatter.ColorLogger(formatter.LogWriter(os.Stdout)) // Only logf parses and evaluates the tagged string and then only // on the format string. This allows angle brackets to appear in // the variadic arguments logger.Logf("This is some text with <em>emphasis</em> in the middle") logger.Logf("This is some text with a <warn>warning</warn> in the middle") logger.Logf("This is some text with a <fail>failure</fail> in the middle") logger.Logf("This is something <success>good</success> that happened") }
Output: This is some text with �[36memphasis�[0m in the middle This is some text with a �[33mwarning�[0m in the middle This is some text with a �[31mfailure�[0m in the middle This is something �[32mgood�[0m that happened
Click to show internal directories.
Click to hide internal directories.