GithubHelp home page GithubHelp logo

gleich / lumber Goto Github PK

View Code? Open in Web Editor NEW
52.0 2.0 4.0 2.37 MB

Easy to use & pretty logger for golang

License: MIT License

Dockerfile 6.00% Makefile 5.53% Go 88.47%
golang logging modules go gomodule

lumber's Introduction

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

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

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

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

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

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

Output an error message.

Demo:

package main

import "github.com/gleich/lumber/v2"

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

Outputs:

errorMsg output

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

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
ExtraNormalOuts Extra normal output destinations (e.g. outputting to a file as well as stdout) []io.Writer{} []io.Writer
ExtraErrOuts Extra error output destinations (e.g. outputting to a file as well as stderr) []io.Writer{} []io.Writer
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

lumber's People

Contributors

actions-user avatar gleich avatar imgbotapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lumber's Issues

Log errors with context

Description

Create a function in format.go that will add a context (string) to the format. Great for fatal and error based logs.

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.

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.