lumber

A feature-rich and easy to use logger for golang.

🚀 Install

Simply run the following from your project root:

go get -u github.com/Matt-Gleich/lumber

🌲 Common Logs

lumber.Success()

Output a success log.

Demo:

package main

import (
    "time"

    "github.com/Matt-Gleich/lumber"
)

func main() {
    lumber.Success("Loaded up the program!")
    time.Sleep(2 * time.Second)
    lumber.Success("Waited 2 seconds!")
}

Outputs:

success

lumber.Info()

Output an info log.

Demo:

package main

import (
    "time"

    "github.com/Matt-Gleich/lumber"
)

func main() {
    lumber.Info("Getting the current year")
    now := time.Now()
    lumber.Info("Current year:", now.Year())
}

Outputs:

info

lumber.Debug()

Output a debug log.

Demo:

package main

import (
    "os"

    "github.com/Matt-Gleich/lumber"
)

func main() {
    homeDir, _ := os.UserHomeDir()
    lumber.Debug("User's home dir is", homeDir)
}

Outputs:

debug

lumber.Warning()

Output a warning log.

Demo:

package main

import (
    "time"

    "github.com/Matt-Gleich/lumber"
)

func main() {
    now := time.Now()
    if now.Year() != 2004 {
        lumber.Warning("Current year isn't 2004")
    }
}

Outputs:

warning

lumber.Error()

Output an error log. If err != nil the error will automatically get logged to the console.

Demo:

package main

import (
    "io/ioutil"

    "github.com/Matt-Gleich/lumber"
)

func main() {
    fName := "invisible-file.txt"
    _, err := ioutil.ReadFile(fName)
    lumber.Error(err, "Failed to read from", fName)
}

Outputs:

error

lumber.ErrorMsg()

Output an error message.

Demo:

package main

import "github.com/Matt-Gleich/lumber"

func main() {
    lumber.ErrorMsg("Ahhh stuff broke")
}

Outputs:

errorMsg

lumber.Fatal()

Output a fatal log. If err != nil the error will automatically get logged to the console and the program will exit (default code is 1).

Demo:

package main

import (
    "io/ioutil"

    "github.com/Matt-Gleich/lumber"
)

func main() {
    fName := "invisible-file.txt"
    _, err := ioutil.ReadFile(fName)
    lumber.Fatal(err, "Failed to read from", fName)
}

Outputs:

fatal

lumber.FatalMsg()

Output a fatal message.

Demo:

package main

import "github.com/Matt-Gleich/lumber"

func main() {
    lumber.FatalMsg("Ahhh stuff broke")
}

Outputs:

fatalMsg

⚙️ Customization

You can customize lumber by changing any of its global variables:

Variable Name Description Default Value Type
lumber.NormalOut The output file for Debug, Success, Warning, and Info os.Stdout *os.File
lumber.ErrOut The output file for Fatal and Error os.Stderr *os.File
lumber.ExitStatus Fatal exit code 1 int
lumber.Padding If the log should have an extra new line at the bottom true bool
lumber.ColoredOutput If the output should have color true bool
lumber.TrueColor If the output colors should be true colors. Default is true if terminal supports it. has256ColorSupport() bool

Example of changing one of these variables:

package main

import "github.com/Matt-Gleich/lumber"

func main() {
    lumber.ColoredOutput = false
    lumber.Debug("See! No color")
}

GitHub