-
Notifications
You must be signed in to change notification settings - Fork 5
Example script
Michael Kenney edited this page Aug 13, 2018
·
1 revision
This is the sample script used in the examples
package main
import (
"fmt"
"os"
"github.com/bdlm/log"
)
func main() {
os.Setenv("HOSTNAME", "myhost")
var logger = log.New()
logger.Level = log.DebugLevel
logger.Out = os.Stdout
// Capture the panic result
defer func() {
err := recover()
if err != nil {
entry := err.(*log.Entry)
logger.WithFields(log.Fields{
"winner": entry.Data["animal"],
"dead": true,
}).Fatal("That could have gone better...")
}
fmt.Printf("\n\n")
}()
fmt.Printf("\n\n")
logger.WithFields(log.Fields{
"animal": "bird",
"count": 1,
}).Debug("Oh, look, a bird...")
logger.WithFields(log.Fields{
"animal": "walrus",
"count": 20,
}).Info("A group of walrus emerges from the ocean")
logger.WithFields(log.Fields{
"animal": "walrus",
"count": 100,
}).Warn("The group's number increased tremendously!")
logger.WithFields(log.Fields{
"animal": "cow",
"count": "wait, what?",
}).Error("Tremendously sized cow enters the ocean.")
logger.WithFields(log.Fields{
"animal": "walrus",
"run": true,
}).Panic("The walrus are attacking!")
}Which one will reach the other side of the river: The one who dreams of a raft, or the one that hitchhikes to the next bridge?