https://github.com/gleich/lumber
Easy to use & pretty logger for golang
https://github.com/gleich/lumber
go golang gomodule logging modules
Last synced: 7 months ago
JSON representation
Easy to use & pretty logger for golang
- Host: GitHub
- URL: https://github.com/gleich/lumber
- Owner: gleich
- License: mit
- Created: 2021-01-14T01:02:54.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-01-04T21:45:18.000Z (over 1 year ago)
- Last Synced: 2025-02-09T06:11:15.233Z (over 1 year ago)
- Topics: go, golang, gomodule, logging, modules
- Language: Go
- Homepage:
- Size: 2.79 MB
- Stars: 53
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
_This project is no longer maintained. Please use [timber](https://github/gleich/timber)._
- [Install](#-install)
- [Logging Functions](#-logging-functions)
- [`lumber.Done()`](#lumberDone)
- [`lumber.Info()`](#lumberinfo)
- [`lumber.Debug()`](#lumberdebug)
- [`lumber.Warning()`](#lumberwarning)
- [`lumber.Error()`](#lumbererror)
- [`lumber.ErrorMsg()`](#lumbererrormsg)
- [`lumber.Fatal()`](#lumberfatal)
- [`lumber.FatalMsg()`](#lumberfatalmsg)
- [Customization](#️-customization)
- [Examples](#-examples)
## Install
Simply run the following from your project root:
```bash
go get -u github.com/gleich/lumber/v3
```
## Logging Functions
### [`lumber.Done()`](https://pkg.go.dev/github.com/gleich/lumber/v3#Done)
Output a "DONE" log.
Demo:
```go
package main
import (
"time"
"github.com/gleich/lumber/v3"
)
func main() {
lumber.Done("booted up the program!")
time.Sleep(2 * time.Second)
lumber.Done("waited 2 seconds!")
}
```
Outputs:

### [`lumber.Info()`](https://pkg.go.dev/github.com/gleich/lumber/v3#Info)
Output an info log.
Demo:
```go
package main
import (
"time"
"github.com/gleich/lumber/v3"
)
func main() {
lumber.Info("Getting the current year")
now := time.Now()
lumber.Info("Current year is", now.Year())
}
```
Outputs:

### [`lumber.Debug()`](https://pkg.go.dev/github.com/gleich/lumber/v3#Debug)
Output a debug log.
Demo:
```go
package main
import (
"os"
"github.com/gleich/lumber/v3"
)
func main() {
homeDir, _ := os.UserHomeDir()
lumber.Debug("User's home dir is", homeDir)
}
```
Outputs:

### [`lumber.Warning()`](https://pkg.go.dev/github.com/gleich/lumber/v3#Warning)
Output a warning log.
Demo:
```go
package main
import (
"time"
"github.com/gleich/lumber/v3"
)
func main() {
now := time.Now()
if now.Year() != 2004 {
lumber.Warning("Current year isn't 2004")
}
}
```
Outputs:

### [`lumber.Error()`](https://pkg.go.dev/github.com/gleich/lumber/v3#Error)
Output an error log with a stack trace.
Demo:
```go
package main
import (
"os"
"github.com/gleich/lumber/v3"
)
func main() {
fname := "invisible-file.txt"
_, err := os.ReadFile(fName)
if err != nil {
lumber.Error(err, "Failed to read from", fname)
}
}
```
Outputs:

### [`lumber.ErrorMsg()`](https://pkg.go.dev/github.com/gleich/lumber/v3#ErrorMsg)
Output an error message.
Demo:
```go
package main
import "github.com/gleich/lumber/v3"
func main() {
lumber.ErrorMsg("Ahhh stuff broke")
}
```
Outputs:

### [`lumber.Fatal()`](https://pkg.go.dev/github.com/gleich/lumber/v3#Fatal)
Output a fatal log with a stack trace.
Demo:
```go
package main
import (
"os"
"github.com/gleich/lumber/v3"
)
func main() {
fName := "invisible-file.txt"
_, err := os.ReadFile(fName)
if err != nil {
lumber.Fatal(err, "Failed to read from", fName)
}
}
```
Outputs:

### [`lumber.FatalMsg()`](https://pkg.go.dev/github.com/gleich/lumber/v3#FatalMsg)
Output a fatal message.
Demo:
```go
package main
import "github.com/gleich/lumber/v3"
func main() {
lumber.FatalMsg("Ahhh stuff broke")
}
```
Outputs:

## Customization
You can customize the logger that lumber uses. Below is an example of some of this customization:
```go
package main
import (
"time"
"github.com/gleich/lumber/v3"
)
func main() {
lumber.SetTimezone(time.Local)
lumber.SetTimeFormat("Mon Jan 2 15:04:05 MST 2006")
lumber.SetFatalExitCode(0)
lumber.Done("Calling from custom logger")
}
```
# Examples
See some examples in the [\_examples/](_examples/) folder.