Documentation
¶
Overview ¶
Package colorine provides a simple feature to print messages to console.
A log line consists of a prefix and a message. The prefix is colored by its content (for example below, "create" is green, "exist" is blue, and "error" is red, and so on.) and the message is not colored.
$ your_program create path/to/file exist path/to/another/file error something went wrong!
By default, no prefix color is defined. You must specify prefix-to-color mapping when you create a Logger. See the Logger's example.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( None = textColor{ct.None, false} Black = textColor{ct.Black, false} Red = textColor{ct.Red, false} Green = textColor{ct.Green, false} Yellow = textColor{ct.Yellow, false} Blue = textColor{ct.Blue, false} Magenta = textColor{ct.Magenta, false} Cyan = textColor{ct.Cyan, false} White = textColor{ct.White, false} BrightBlack = textColor{ct.Black, true} BrightRed = textColor{ct.Red, true} BrightGreen = textColor{ct.Green, true} BrightYellow = textColor{ct.Yellow, true} BrightBlue = textColor{ct.Blue, true} BrightMagenta = textColor{ct.Magenta, true} BrightCyan = textColor{ct.Cyan, true} BrightWhite = textColor{ct.White, true} )
Text color constants. Use these to build a TextStyle.
var ( Verbose = TextStyle{White, None} Info = TextStyle{Green, None} Notice = TextStyle{Blue, None} Warn = TextStyle{Yellow, None} Error = TextStyle{Red, None} Default = TextStyle{Green, None} )
Predefined TextStyles. Of course you can ignore these.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct { // Prefix string to TextStyle mapping. Prefixes Prefixes // contains filtered or unexported fields }
A Logger handles the printing stuff. You can create one with NewLogger().
Example ¶
logger := colorine.NewLogger( colorine.Prefixes{ // Using colorine's predefined TextStyles "create": colorine.Info, "exist": colorine.Notice, // Or specify your own "debug": colorine.TextStyle{colorine.White, colorine.None}, "error": colorine.TextStyle{colorine.BrightRed, colorine.White}, }, // The default prefix color colorine.TextStyle{colorine.Green, colorine.None}, ) logger.Log("create", "path/to/file") logger.Log("exist", "path/to/another/file") logger.Log("error", "something went wrong!")
Output:
func NewLogger ¶
NewLogger creates a new Logger. prefixes is a prefix-string-to-text-style mapping. The log prefix is colored using this table. If no entry is found in prefixes, defaultStyle is used.
By default, no prefix is registered to any text style.