-
Notifications
You must be signed in to change notification settings - Fork 4
/
interfaces.go
42 lines (34 loc) · 1014 Bytes
/
interfaces.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
package home
import (
"bytes"
"fmt"
"log"
"runtime"
"strings"
)
type ErrorHandler interface {
Error(e error)
}
type defaultErrorHandler struct{}
func (d defaultErrorHandler) Error(e error) {
buf := make([]byte, 1000000)
runtime.Stack(buf, false)
buf = bytes.Trim(buf, "\x00")
stack := string(buf)
stackParts := strings.Split(stack, "\n")
newStackParts := []string{stackParts[0]}
newStackParts = append(newStackParts, stackParts[3:]...)
stack = strings.Join(newStackParts, "\n")
log.Println("ERROR", e.Error()+"\n"+stack)
}
type Logger interface {
InfoF(category string, message string, args ...interface{})
DebugF(category string, message string, args ...interface{})
}
type defaultLogger struct{}
func (d defaultLogger) InfoF(category string, message string, args ...interface{}) {
log.Println(category+":", fmt.Sprintf(message, args...))
}
func (d defaultLogger) DebugF(category string, message string, args ...interface{}) {
log.Println(category+":", fmt.Sprintf(message, args...))
}