Gleich Lumber Save

🪵 A dead simple, pretty, and feature-rich logger for golang

Project README

🪵 lumber 🪵

Godoc Reference test workflow result lint workflow result
GitHub go.mod Go version Golang report card

A dead simple, pretty, and feature-rich logger for golang

🚀 Install

Simply run the following from your project root:

go get -u github.com/gleich/lumber/v2

🌲 Logging Functions

lumber.Success()

Output a success log.

Demo:

package main

import (
    "time"

    "github.com/gleich/lumber/v2"
)

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

Outputs:

success output

lumber.Info()

Output an info log.

Demo:

package main

import (
    "time"

    "github.com/gleich/lumber/v2"
)

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

Outputs:

info output

lumber.Debug()

Output a debug log.

Demo:

package main

import (
    "os"

    "github.com/gleich/lumber/v2"
)

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

Outputs:

debug output

lumber.Warning()

Output a warning log.

Demo:

package main

import (
    "time"

    "github.com/gleich/lumber/v2"
)

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

Outputs:

warning output

lumber.Error()

Output an error log with a stack trace.

Demo:

package main

import (
    "os"

    "github.com/gleich/lumber/v2"
)

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

Outputs:

error output

lumber.ErrorMsg()

Output an error message.

Demo:

package main

import "github.com/gleich/lumber/v2"

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

Outputs:

errorMsg output

lumber.Fatal()

Output a fatal log with a stack trace.

Demo:

package main

import (
    "os"

    "github.com/gleich/lumber/v2"
)

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

Outputs:

fatal output

lumber.FatalMsg()

Output a fatal message.

Demo:

package main

import "github.com/gleich/lumber/v2"

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

Outputs:

fatalMsg output

⚙️ Customization

You can customize lumber by creating a custom logger and changing values on it. You then call the log functions on the custom logger. Below is an example of this.

package main

import "github.com/gleich/lumber/v2"

func main() {
    log := lumber.NewCustomLogger()
    log.ColoredOutput = false
    log.ExitCode = 2

    log.Success("Calling from custom logger!")
}

Here are all the variables that can be changed:

Variable Name Description Default Value Type
NormalOut The output file for Debug, Success, Warning, and Info os.Stdout *os.File
ErrOut The output file for Fatal and Error os.Stderr *os.File
ExtraNormalOuts Extra normal output destinations (e.g. outputting to a file as well as stdout) []io.Writer{} []io.Writer
ExtraErrOuts Extra error output destinations (e.g. outputting to a file as well as stderr) []io.Writer{} []io.Writer
ExitCode Fatal exit code 1 int
Padding If the log should have an extra new line at the bottom false bool
ColoredOutput If the output should have color true bool
TrueColor If the output colors should be true colors. Default is true if terminal supports it. has256ColorSupport() bool
ShowStack If stack traces should be shown true bool
Multiline If the should should be spread out to more than one line false bool
Timezone Timezone you want the times to be logged in time.UTC *time.Location

✨ Examples

See some examples in the examples/ folder! Just run them using go run main.go.

🙌 Contributing

Before contributing please read the CONTRIBUTING.md file.

👥 Contributors

Open Source Agenda is not affiliated with "Gleich Lumber" Project. README Source: gleich/lumber
Stars
52
Open Issues
0
Last Commit
1 year ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating