# README
Install
Simply run the following from your project root:
go get -u github.com/gleich/lumber/v3
Logging Functions
lumber.Done()
Output a "DONE" log.
Demo:
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()
Output an info log.
Demo:
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()
Output a debug log.
Demo:
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()
Output a warning log.
Demo:
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()
Output an error log with a stack trace.
Demo:
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()
Output an error message.
Demo:
package main
import "github.com/gleich/lumber/v3"
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/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()
Output a fatal message.
Demo:
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:
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/ folder.
# Functions
Output a INFO log message.
Output a DONE log message.
Output a ERROR log message with information about the error.
Output a ERROR log message.
Output a FATAL log message with information about the error.
Output a FATAL log message.
Output a INFO log message.
Set the colors used for logging.
Set the output or Fatal, FatalMsg, Error, and ErrorMsg.
Set the extra normal out destinations (e.g.
Set the extra normal out destinations (e.g.
Set the exit code used by Fatal and FatalMsg.
Set the output or Debug, Done, Warning, and Info.
Set if the stack trace should be shown or not when calling Error or Fatal.
Set the time format
Default is 2006/01/02 15:04:05 MST.
Set the timezone
Default is time.UTC.
Output a WARN log message.