File tree Expand file tree Collapse file tree 3 files changed +18
-17
lines changed Expand file tree Collapse file tree 3 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ func NewEchoLoggerMiddleware() echo.MiddlewareFunc {
294
294
"latency_ms" : latency .Milliseconds (),
295
295
"referer" : req .Referer (),
296
296
"type" : LogTypeAPI ,
297
- "request_id" : GetCorrelationID (ctx ),
297
+ "request_id" : getCorrelationID (ctx ),
298
298
"error" : errStr ,
299
299
}
300
300
@@ -326,7 +326,7 @@ func LogWithEchoContext(c echo.Context, content ...interface{}) {
326
326
327
327
logField := logrus.Fields {
328
328
"type" : logType ,
329
- "request_id" : GetCorrelationID (c .Request ().Context ()),
329
+ "request_id" : getCorrelationID (c .Request ().Context ()),
330
330
}
331
331
332
332
if len (content ) > 2 {
Original file line number Diff line number Diff line change @@ -21,10 +21,19 @@ const (
21
21
22
22
// custom constants
23
23
const (
24
- DefaultTimestampFormat = "2006-01-02T15 :04:05.00000Z07:00 "
24
+ DefaultTimestampFormat = "2006-01-02 15 :04:05.00000 "
25
25
DefaultGormSourceField = "source"
26
26
)
27
27
28
+ // Key is key context type
29
+ type Key string
30
+
31
+ // Exported constanst
32
+ const (
33
+ CorrelationIDKey Key = "X-User-Correlation-Id"
34
+ RequestIDKey Key = "X-Request-ID"
35
+ )
36
+
28
37
// LogFormat log format
29
38
type LogFormat uint32
30
39
@@ -86,6 +95,7 @@ type Logger struct {
86
95
87
96
// SetFormatter logger formatter
88
97
func (l * Logger ) SetFormatter (logFormat LogFormat ) {
98
+ l .logFormat = logFormat
89
99
switch logFormat {
90
100
case JSONFormat :
91
101
l .Logger .SetFormatter (& log.JSONFormatter {TimestampFormat : DefaultTimestampFormat })
@@ -142,7 +152,7 @@ func (l *Logger) SetLevel(level Level) {
142
152
143
153
func getDefaultFileConfig () * FileConfig {
144
154
return & FileConfig {
145
- Filename : GetLogFile (),
155
+ Filename : getLogFile (),
146
156
MaxSize : 10 ,
147
157
MaxBackups : 3 ,
148
158
MaxAge : 30 ,
Original file line number Diff line number Diff line change @@ -9,31 +9,22 @@ import (
9
9
"time"
10
10
)
11
11
12
- // Key is key context type
13
- type Key string
14
-
15
- // Exported constanst
16
- const (
17
- CorrelationIDKey Key = "X-User-Correlation-Id"
18
- RequestIDKey Key = "X-Request-ID"
19
- )
20
-
21
12
// withCorrelationID sets correlation id to context
22
13
func withCorrelationID (parent context.Context , correlationID string ) context.Context {
23
14
return context .WithValue (parent , CorrelationIDKey , correlationID )
24
15
}
25
16
26
- // GetCorrelationID return correlation id
27
- func GetCorrelationID (ctx context.Context ) string {
17
+ // getCorrelationID return correlation id
18
+ func getCorrelationID (ctx context.Context ) string {
28
19
id := ctx .Value (CorrelationIDKey )
29
20
if id != nil {
30
21
return id .(string )
31
22
}
32
23
return ""
33
24
}
34
25
35
- // GetLogFile get file log
36
- func GetLogFile () string {
26
+ // getLogFile get file log
27
+ func getLogFile () string {
37
28
path := ""
38
29
dir , err := os .Getwd ()
39
30
if err != nil {
You can’t perform that action at this time.
0 commit comments