-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
45 lines (38 loc) · 985 Bytes
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package web
import (
"errors"
"fmt"
"log"
"os"
"github.com/deferpanic/deferclient/deferstats"
)
var (
dfs *deferstats.Client
)
// NewLogger configures defer panic error and starts capturing stats.
// It looks for DEFERPANIC_KEY,
// DEVERPANIC_ENVIRONMENT and DEFERPANIC_APPGROUP environment vars
func NewLogger() {
dfs = deferstats.NewClient(os.Getenv("DEFERPANIC_API_KEY"))
dfs.Setenvironment(os.Getenv("DEFERPANIC_ENVIRONMENT"))
dfs.SetappGroup(os.Getenv("DEFERPANIC_APPGROUP"))
go dfs.CaptureStats()
}
func logError(msg string) {
err := errors.New(msg)
if err != nil {
dfs.Wrap(err)
log.Println(err)
}
}
// LogError passes the error to deferpanic
// and prints the error message to stdout
func LogError(e error) {
logError(e.Error())
}
// LogErrorf accepts a format string and arguments
// It creates a new error, logs with deferpanic and
// prints the error to stdout
func LogErrorf(format string, a ...interface{}) {
LogError(fmt.Errorf(format, a...))
}