forked from zllangct/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
48 lines (40 loc) · 757 Bytes
/
Copy pathlogger.go
File metadata and controls
48 lines (40 loc) · 757 Bytes
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
46
47
package ecs
import (
"fmt"
"log"
"os"
"runtime"
)
type IInternalLogger interface {
Info(v ...interface{})
Error(v ...interface{})
Fatal(v ...interface{})
}
type StdLogger struct {
logger *log.Logger
}
func NewStdLogger() *StdLogger {
return &StdLogger{
logger: log.New(os.Stdout, "", log.Lshortfile),
}
}
func (p StdLogger) Info(v ...interface{}) {
p.logger.Output(2, fmt.Sprint(v...))
}
func (p StdLogger) Error(v ...interface{}) {
buf := make([]byte, 1024)
for {
n := runtime.Stack(buf, false)
if n < len(buf) {
buf = buf[:n]
break
}
buf = make([]byte, 2*len(buf))
}
s := fmt.Sprint(append(v, "\n", string(buf))...)
p.logger.Output(2, s)
}
func (p StdLogger) Fatal(v ...interface{}) {
p.Error(v...)
os.Exit(1)
}