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

🪵 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
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

Owner
Matt Gleich
I'm a 17-year-old thats building scalable, multi-platform applications using cutting-edge frameworks and technologies. 100% self-taught 🚀
Matt Gleich
Comments
  • Multiple Writers

    Multiple Writers

    Description

    New Logger structs for outputting to extra io.Writers (one for normal logs and one for error logs).

    Steps

    • [x] My change requires a change to the documentation
    • [x] I have updated the accessible documentation according
    • [x] I have read the CONTRIBUTING.md file
    • [x] There is no duplicate open or closed pull request for this fix/addition/issue resolution.

    Original Issue

    This PR resolves #8

  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 33% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /images/error.png | 145.14kb | 87.68kb | 39.59% | | /images/fatal.png | 141.04kb | 85.31kb | 39.51% | | /images/info.png | 30.04kb | 22.57kb | 24.86% | | /images/success.png | 31.39kb | 23.89kb | 23.89% | | /images/debug.png | 19.03kb | 15.92kb | 16.32% | | /images/warning.png | 18.42kb | 15.62kb | 15.20% | | /images/fatalMsg.png | 17.29kb | 14.82kb | 14.30% | | /images/errorMsg.png | 17.57kb | 15.15kb | 13.74% | | | | | | | Total : | 419.92kb | 280.97kb | 33.09% |


    📝 docs | :octocat: repo | 🙋🏾 issues | 🏪 marketplace

    ~Imgbot - Part of Optimole family

  • [ImgBot] Optimize images

    [ImgBot] Optimize images

  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 63% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /images/fatal.png | 232.34kb | 80.82kb | 65.21% | | /images/fatalHook.png | 244.31kb | 85.35kb | 65.06% | | /images/errorHook.png | 240.15kb | 84.28kb | 64.91% | | /images/error.png | 223.88kb | 79.20kb | 64.63% | | /images/info.png | 53.26kb | 22.70kb | 57.37% | | /images/success.png | 55.44kb | 23.91kb | 56.87% | | /images/warning.png | 31.61kb | 16.59kb | 47.53% | | /images/debug.png | 30.77kb | 16.18kb | 47.42% | | /images/errorMsg.png | 27.21kb | 14.89kb | 45.28% | | | | | | | Total : | 1,138.97kb | 423.91kb | 62.78% |


    Black Lives Matter | 💰 donate | 🎓 learn | ✍🏾 sign

    📝 docs | :octocat: repo | 🙋🏾 issues | 🏅 swag | 🏪 marketplace

  • Add options

    Add options

    Description

    For each status add a function to Log and to Chop. A log is a simple output and a Chop is a log only if err != nil. Chop for Fatal should have an option to auto exit the program with an exit status of 1.

Dead simple, super fast, zero allocation and modular logger for Golang

Onelog Onelog is a dead simple but very efficient JSON logger. It is one of the fastest JSON logger out there. Also, it is one of the logger with the

Sep 26, 2022
Logger - Simple logger without written with std pkg

Go-Logger Simple usage is: package main

Jan 2, 2022
Convenient Logger interface and std logger wrapper

Convenient logger interface and wrapper around std logger Interface type Logger interface { Error(err error) Debugf(format string, args ...interface

Nov 28, 2021
Logger - A thin wrapper of uber-go/zap logger for personal project

a thin wraper of uber-go/zap logger for personal project 0. thanks uber-go/zap B

Sep 17, 2022
Litter is a pretty printer library for Go data structures to aid in debugging and testing.

Litter Litter is a pretty printer library for Go data structures to aid in debugging and testing. Litter is provided by Sanity: The Headless CMS Const

Dec 28, 2022
Golang Rich Error, for having better visibility when things don't work as expected.

Rich Error Why we need better error handling? the error messages in go are ugly and very hard to read, also they don't give us much data about what ex

Dec 19, 2022
A simple logging module for go, with a rotating file feature and console logging.

A simple logging module for go, with a rotating file feature and console logging. Installation go get github.com/jbrodriguez/mlog Usage Sample usage W

Dec 14, 2022
Package httpretty prints the HTTP requests you make with Go pretty on your terminal.

httpretty Package httpretty prints the HTTP requests of your Go programs pretty on your terminal screen. It is mostly inspired in curl's --verbose mod

Jan 8, 2023
Implements a deep pretty printer for Go data structures to aid in debugging

go-spew Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is

Jan 9, 2023
Colored pretty printer for Go language
Colored pretty printer for Go language

pp Colored pretty printer for Go language Usage Just call pp.Print(). import "github.com/k0kubun/pp" m := map[string]string{"foo": "bar", "hello": "w

Dec 29, 2022
Implements a deep pretty printer for Go data structures to aid in debugging

spew Spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provi

Dec 25, 2022
A simple and super power logger for golang
A simple and super power logger for golang

The most powerfull and faster logger for golang powered by DC ?? What is this? W

Oct 18, 2022
Golog is a logger which support tracing and other custom behaviors out of the box. Blazing fast and simple to use.

GOLOG Golog is an opinionated Go logger with simple APIs and configurable behavior. Why another logger? Golog is designed to address mainly two issues

Oct 2, 2022
Errr - Errr (The Rich Structured Error Package missing from Go)

The errr package was created to fill the gap between error handling and error reporting.

Feb 7, 2022
A Simple logger for golang

go-logger Installation go get github.com/mo-taufiq/go-logger Quickstart package main import ( gologger "github.com/mo-taufiq/go-logger" ) func main

Dec 14, 2022
Simple logger for Go programs. Allows custom formats for messages.
Simple logger for Go programs. Allows custom formats for messages.

go-logger A simple go logger for easy logging in your programs. Allows setting custom format for messages. Preview Install go get github.com/apsdehal/

Dec 17, 2022
Simple Yet Powerful Logger

sypl sypl provides a Simple Yet Powerful Logger built on top of the Golang sypl. A sypl logger can have many Outputs, and each Output is responsible f

Sep 23, 2022
simple concurrent logger

XMUS-LOGGER pure golang logger compatible with golang io standards. USAGE : logOptions := logger.LoggerOptions{ LogLevel: 6, // read more about lo

Aug 1, 2022
A simple logger API.

flog a simple logger API for Go program that save logs into a file. NOTE: This package is provided "as is" with no guarantee. Use it at your own risk

May 14, 2022