-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
34 lines (28 loc) · 869 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
package main
import (
"net/http"
"github.com/johnamadeo/server"
log "github.com/sirupsen/logrus"
)
func LogAndWriteErr(w http.ResponseWriter, err error, status int, function string) {
log.WithFields(log.Fields{
"logger": "logrus",
"status": status,
"function": function,
}).Error(err)
w.WriteHeader(status)
w.Write(server.ErrToBytes(err))
}
func LogAndWrite(w http.ResponseWriter, bytes []byte, status int, function string) {
log.WithFields(log.Fields{
"logger": "logrus",
"function": function,
}).Debug(status)
w.Write(bytes)
}
func LogAndWriteStatusBadRequest(w http.ResponseWriter, err error, function string) {
LogAndWriteErr(w, err, http.StatusBadRequest, function)
}
func LogAndWriteStatusInternalServerError(w http.ResponseWriter, err error, function string) {
LogAndWriteErr(w, err, http.StatusInternalServerError, function)
}