A feature-rich and easy to use logger for golang

πŸͺ΅ lumber πŸͺ΅

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

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 output

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 output

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 output

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 output

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 output

lumber.ErrorMsg()

Output an error message.

Demo:

package main

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

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

Outputs:

errorMsg output

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 output

lumber.FatalMsg()

Output a fatal message.

Demo:

package main

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

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

Outputs:

fatalMsg output

βš™οΈ 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")
}

⏰ Changing the log time

All normal log functions have a twin function that accepts a custom time. All of these functions are suffixed with WithTime.

πŸ™Œ Contributing

Before contributing please read the CONTRIBUTING.md file.

πŸ‘₯ Contributors

Owner
Matthew Gleich
I'm a 16-year-old thats building scalable, multi-platform applications using cutting edge frameworks and technologies. 100% self taught πŸš€
Matthew 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.

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 - Simple logger without written with std pkg

Go-Logger Simple usage is: package main

Jan 2, 2022
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
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
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
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 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
Clean architecture starter pack for faster and easier feature creation using Go.
Clean architecture starter pack for faster and easier feature creation using Go.

cleanarchGo ?? About Clean architecture starter pack for faster and easier feature creation using Go. This pack includes Clean Architecture with the E

May 8, 2023
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
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
HTTP request logger for Golang
HTTP request logger for Golang

Horus ?? Introduction Horus is a request logger and viewer for Go. It allows developers log and view http requests made to their web application. Inst

Dec 27, 2022
A project that adds color to golang's logger module

logger A project that adds color to golang's log module Installation go get github.com/christopher18/logger Usage // Import the module import "github

Dec 28, 2021
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
Go-l3 - Lightweight Levelled Logger for Golang

Go-l3 - Lightweight Levelled Logger for Golang

Dec 13, 2022
A 12-factor app logger built for performance and happy development
A 12-factor app logger built for performance and happy development

logxi log XI is a structured 12-factor app logger built for speed and happy development. Simpler. Sane no-configuration defaults out of the box. Faste

Nov 27, 2022
A minimal and extensible structured logger

⚠️ PRE-RELEASE ⚠️ DO NOT IMPORT THIS MODULE YOUR PROJECT WILL BREAK package log package log provides a minimal interface for structured logging in ser

Jan 7, 2023
A customized GORM logger that implements the appropriate interface and uses Logrus to output logs

CryptoMath GORM Logger A customized GORM logger that implements the appropriate interface and uses Logrus to output logs. Install go get github.com/ma

Nov 6, 2021
logger wraps uber/zap and trace with opentelemetry

logger 特性 ζ”―ζŒ uber/zap ζ—₯εΏ— ζ”―ζŒ log rollingοΌŒδ½Ώη”¨ lumberjace ζ”―ζŒζ—₯εΏ—θΏ½θΈͺ ζ”―ζŒdebug、info、warn、e

Sep 17, 2022
This package enables json output, level logging and so on to standard go logger.

logplug This package enables json output, level logging and so on to standard logger. Usage log.SetOutput(logplug.NewJSONPlug(os.Stderr, logplug.LogF

Dec 27, 2021