forked from dolab/gogo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
50 lines (38 loc) · 864 Bytes
/
logger.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
46
47
48
49
50
package gogo
import (
"log"
"path"
"github.com/dolab/logger"
)
// AppLogger implements Logger interface
type AppLogger struct {
*logger.Logger
requestId string
}
func NewAppLogger(output, filename string) *AppLogger {
switch output {
case "stdout", "stderr", "null", "nil":
// skip
default:
if output[0] != '/' {
output = path.Join(output, filename+".log")
}
}
l, err := logger.New(output)
if err != nil {
log.Printf("logger.New(%s): %v\n", output, err)
return nil
}
logger := &AppLogger{l, ""}
return logger
}
// New returns a new Logger with provided requestId which shared writer with current logger
func (l *AppLogger) New(requestId string) Logger {
copied := *l
copied.Logger = copied.Logger.New(requestId)
copied.requestId = requestId
return &copied
}
func (l *AppLogger) RequestId() string {
return l.requestId
}