Git Product home page Git Product logo

lumber's Introduction

๐Ÿชต 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

lumber's People

Contributors

actions-user avatar gleich avatar imgbotapp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.