-
π Install -
π² Common Logs -
βοΈ Customization -
β° Changing the log time -
π Contributing -
π₯ Contributors
π
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:
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:
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:
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:
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:
lumber.ErrorMsg()
Output an error message.
Demo:
package main
import "github.com/Matt-Gleich/lumber"
func main() {
lumber.ErrorMsg("Ahhh stuff broke")
}
Outputs:
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:
lumber.FatalMsg()
Output a fatal message.
Demo:
package main
import "github.com/Matt-Gleich/lumber"
func main() {
lumber.FatalMsg("Ahhh stuff broke")
}
Outputs:
βοΈ
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.