-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.go
79 lines (67 loc) · 1.61 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package kpx
import (
"fmt"
"github.com/ccding/go-logging/logging"
"os"
"strings"
"time"
)
const (
logFormat = "%s %s\n time,message"
timeFormat = "2006/01/02 15:04:05"
)
func logInit() {
var err error
logger, err = logging.CustomizedLogger("main", logging.NOTSET, logFormat, timeFormat, os.Stdout, false, logging.DefaultQueueSize, logging.DefaultRequestSize, logging.DefaultBufferSize, logging.DefaultTimeInterval)
if err != nil {
fmt.Printf("Error: unable to create logger: %v", err)
os.Exit(1)
}
}
func logDestroy() {
logger.Destroy()
}
func logFlush() {
logger.Flush()
}
func logPrintf(format string, a ...any) {
format = fmt.Sprintf("%s %s", time.Now().Format(timeFormat), format)
fmt.Printf(format, a...)
}
func logHeader(format string, prefix string, header string) {
lower := strings.ToLower(header)
if strings.HasPrefix(lower, "proxy-authorization:") {
l := len(header)
if l-10 > 50 {
l = 50
} else {
l = l - 10
if l < 20 {
l = 20
}
}
header = header[:l] + "..."
}
logger.Infof(format, prefix, header)
}
type traceInfo struct {
reqId int32
name string
}
func newTraceInfo(reqId int32, name string) *traceInfo {
return &traceInfo{reqId, name}
}
func logTrace(ti *traceInfo, format string, args ...interface{}) {
logger.Debugf(fmt.Sprintf("(%d) %s: %s", ti.reqId, ti.name, format), args...)
}
func logInfo(format string, args ...interface{}) {
logger.Infof(format, args...)
}
func logError(format string, args ...interface{}) {
logger.Errorf(format, args...)
}
func logFatal(format string, args ...interface{}) {
logger.Fatalf(format, args...)
logger.Destroy()
os.Exit(1)
}