🚀
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:
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:
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:
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:
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:
lumber.ErrorMsg()
Output an error message.
Demo:
package main
import "github.com/gleich/lumber/v2"
func main() {
lumber.ErrorMsg("Ahhh stuff broke")
}
Outputs:
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:
lumber.FatalMsg()
Output a fatal message.
Demo:
package main
import "github.com/gleich/lumber/v2"
func main() {
lumber.FatalMsg("Ahhh stuff broke")
}
Outputs:
⚙️
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.