A feature-rich and easy to use logger for golang

Overview

πŸͺ΅ 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

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

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

Go-Logger Simple usage is: package main

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

tsingson 0 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

Damiano Petrungaro 35 Sep 10, 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
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
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 26 Sep 2, 2022
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 401 Sep 13, 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 6 Jun 26, 2022
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

Michael Okoh 80 Aug 15, 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

null 0 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

Moh Taufiqur Rohman 1 Jan 15, 2022
Go-l3 - Lightweight Levelled Logger for Golang

Go-l3 - Lightweight Levelled Logger for Golang

nandlabs 1 Jan 20, 2022
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

Mario Gutierrez 350 Sep 1, 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

Go kit 119 Sep 16, 2022
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

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

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

xiaolei 8 Aug 28, 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

Koumei Mikuni 0 Dec 27, 2021
Goal is to generate logger and tracer wraps around a certain struct

Goal is to generate logger and tracer wraps around a certain struct

null 0 Feb 13, 2022