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

Overview

🪵 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

Issues
  • 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

    enhancement 
    opened by gleich 0
  • [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

    opened by imgbot[bot] 0
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    opened by imgbot[bot] 0
  • [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

    opened by imgbot[bot] 0
  • 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.

    enhancement 
    opened by gleich 0
Releases(v2.2.0)
  • v2.2.0(Dec 13, 2021)

  • v2.1.2(Sep 26, 2021)

  • v2.1.1(Sep 25, 2021)

  • v2.1.0(Sep 25, 2021)

  • v2.0.1(Sep 24, 2021)

  • v2.0.0(Sep 24, 2021)

    • Automatic err if nil has been phased out as it's an antipattern.
    • Logs are now single line. To get back to the multiline version please use the lumber.Multiline option.
    • WithTime functions have been phased out as they don't serve a purpose.
    • New examples are now provided
    Source code(tar.gz)
    Source code(zip)
  • v1.1.4(Jul 29, 2021)

  • v1.1.3(Jun 4, 2021)

  • v1.1.2(Apr 14, 2021)

  • v1.1.1(Feb 19, 2021)

  • v1.1.0(Jan 17, 2021)

  • v1.0.0(Jan 16, 2021)

    Here are some of the core features: :rainbow: 256 or 16 bit color for quick identification of certain log types. :alarm_clock: Custom and automatic timestamps. 🪝 Hooks! Run code before lumber log the error. Never write another if err != nil again!! :page_facing_up: Super clean and informative docs (thanks @safinsingh and @cjdenio for the feedback!) 🪵 Pass multiple items into a log which will automatically be separated with spaces. :pancakes: Automatic stack traces for errors. :dizzy_face: Program exits automatically after fatal logs. :gear: Customize almost everything!

    Source code(tar.gz)
    Source code(zip)
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
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

Francois Parquet 399 Jun 16, 2022
Logger - Simple logger without written with std pkg

Go-Logger Simple usage is: package main

MaskedTrench 2 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

Denis Mitrofanov 1 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

tsingson 1 Jun 16, 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

Sanity 1.3k Jun 15, 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

Henrique Vicente 257 Jun 15, 2022
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

Dave Collins 5k Jun 20, 2022
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

Takashi Kokubun 1.3k Jun 23, 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

null 87 Jun 27, 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

Peyman Goldasteh 12 Jun 10, 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

Juan B. Rodriguez 25 Jun 11, 2022
A simple and super power logger for golang

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

Teo 7 Jan 23, 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.

Hamed Momeni 2 Feb 7, 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

Damiano Petrungaro 34 Jun 22, 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

Moh Taufiqur Rohman 1 Jan 15, 2022
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/

Amanpreet Singh 276 Jun 14, 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

Sauce Labs 9 Apr 28, 2022
simple concurrent logger

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

amupxm [amir hossein mokarrami far] 5 Sep 19, 2021
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

Iss Meftah 3 May 14, 2022