console.go: github.com/guillaumewuip/console.go Index | Examples | Files | Directories

package console

import "github.com/guillaumewuip/console.go"

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

Examples

Package Files

colors.go console.go hooks.go logger.go

type ColorsOptions Uses

type ColorsOptions map[string]string

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 Uses

type HookFunc func(Logger) error

A Hook implements a function fired each time a log is printed. It receives a Logger.

Here's an example showing how to received all logs.

Code:


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)

type Location Uses

type Location struct {
    Filename string
    Line     int
}

A log location.

Stores filename and line of the log call

type Logger Uses

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 Uses

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 :

Create a new console with default colors

Code:

myConsole := console.NewConsole(console.ColorsOptions{})

Create a new console with custom colors

Code:

colors := console.ColorsOptions{
    "Log": "green+i:black",
}

myConsole := console.NewConsole(colors)

func (*Logger) AddHook Uses

func (logger *Logger) AddHook(hook HookFunc)

Method to add a hook to a console

func (*Logger) Error Uses

func (logger *Logger) Error(msg string, args ...interface{})

Error level

console.Error("Hello World")

func (*Logger) File Uses

func (logger *Logger) File() *Logger

Add file and line information to the log

console.File().Log("Something") //[main.go:22]	Something

func (*Logger) Info Uses

func (logger *Logger) Info(msg string, args ...interface{})

Info level

console.Info("Hello World")

func (*Logger) Log Uses

func (logger *Logger) Log(msg string, args ...interface{})

Log level

console.Log("Hello World")

func (*Logger) Tag Uses

func (logger *Logger) Tag(args ...string) *Logger

Add tags to the log

console.Tag("Tag1", "Tag2").Log("Something") //[Tag1][Tag2]	Something

func (*Logger) Time Uses

func (logger *Logger) Time() *Logger

Add time information to the log

console.Time().Log("Something") //2015-02-15T10:31:46+01:00	Something

func (*Logger) Warning Uses

func (logger *Logger) Warning(msg string, args ...interface{})

Warn level

console.Warn("Hello World")

Directories

PathSynopsis
examples

Package console imports 6 packages (graph) and is imported by 2 packages. Updated 2016-07-16. Refresh now. Tools for package owners.