Documentation ¶
Overview ¶
Console is a lightweight logging tool inspired by the NodeJS console object and http://github.com/bluejamesbond/scribe.js project.
console.Info("Some info") console.Tag("Hello").Time().File().Log("Hello %s", "World")
Console provided Info, Log, Warning and Error method and Tag, Time, File optional information ¶
With use of ansi colors, it output something like below in terminal :
[Tag1][Tag2] [main.go:48] 2015-02-15T09:22:06+01:00 Hello World
Author: http://github.com/guillaumewuip
Index ¶
- type ColorsOptions
- type HookFunc
- type Location
- type Logger
- func (logger *Logger) AddHook(hook HookFunc)
- func (logger *Logger) Error(msg string, args ...interface{})
- func (logger *Logger) File() *Logger
- func (logger *Logger) Info(msg string, args ...interface{})
- func (logger *Logger) Log(msg string, args ...interface{})
- func (logger *Logger) Tag(args ...string) *Logger
- func (logger *Logger) Time() *Logger
- func (logger *Logger) Warning(msg string, args ...interface{})
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColorsOptions ¶
Logger colors
Uses colors from the https://github.com/mgutz/ansi package
Default values are :
ColorsOptions{ "Log": "green:black", "Info": "cyan:black", "Error": "red:black", "Warning": "yellow:black", }
type HookFunc ¶
A Hook implements a function fired each time a log is printed. It receives a Logger.
Example ¶
Here's an example showing how to received all logs.
testHook := func(logger console.Logger) error { fmt.Printf( "Test hook fired. Message=%s, Level=%s, File=%s \n", logger.Message, logger.Level, logger.Location.Filename, ) return nil } myConsole.AddHook(testHook)
Output:
type Logger ¶
type Logger struct { Level string Tags []string Timestamp int64 ContextMessage string Message string Location // contains filtered or unexported fields }
Logger struct stores log params up to the print
func NewConsole ¶
func NewConsole(colors ColorsOptions) *Logger
Create a new console
myConsole = console.NewConsole(console.ColorsOptions{})
Pass a ColorsOptions map (could be empty to use default values).
Colors from https://github.com/mgutz/ansi. See examples below :
Example ¶
Create a new console with default colors
myConsole := console.NewConsole(console.ColorsOptions{})
Output:
Example (WithCustomColors) ¶
Create a new console with custom colors
colors := console.ColorsOptions{ "Log": "green+i:black", } myConsole := console.NewConsole(colors)
Output:
func (*Logger) File ¶
Add file and line information to the log
console.File().Log("Something") //[main.go:22] Something
func (*Logger) Tag ¶
Add tags to the log
console.Tag("Tag1", "Tag2").Log("Something") //[Tag1][Tag2] Something
Directories ¶
Path | Synopsis |
---|---|
Godeps
|
|
_workspace/src/github.com/mgutz/ansi
Small, fast library to create ANSI colored strings and codes.
|
Small, fast library to create ANSI colored strings and codes. |