console.go: Index | Examples | Files | Directories

package console

import ""

Console is a lightweight logging tool inspired by the NodeJS console object and 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




Package Files

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

type ColorsOptions Uses

type ColorsOptions map[string]string

Logger colors

Uses colors from the package

Default values are :

   "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.


testHook := func(logger console.Logger) error {

        "Test hook fired. Message=%s, Level=%s, File=%s \n",

    return nil


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

    // 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 See examples below :

Create a new console with default colors


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

Create a new console with custom colors


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")



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