@@ -57,43 +57,17 @@ func RequestLoggingWithEcho(config *Config) echo.MiddlewareFunc {
57
57
}
58
58
}
59
59
60
- // SetContext for CloudFunctions
61
- func SetContext (config * Config , w http.ResponseWriter , r * http.Request ) (http.ResponseWriter , * http.Request ) {
62
- before := time .Now ()
63
-
64
- traceId := getTraceId (r )
65
- if traceId == "" {
66
- // there is no span yet, so create one
67
- var ctx context.Context
68
- traceId , ctx = generateTraceId (r )
69
- r = r .WithContext (ctx )
70
- }
71
-
72
- traces := fmt .Sprintf ("projects/%s/traces/%s" , config .ProjectId , traceId )
73
-
74
- contextLogger := & ContextLogger {
75
- out : config .ContextLogOut ,
76
- Trace : traces ,
77
- Severity : config .Severity ,
78
- AdditionalData : config .AdditionalData ,
79
- loggedSeverity : make ([]Severity , 0 , 10 ),
80
- Skip : config .Skip ,
81
- }
82
- ctx := context .WithValue (r .Context (), contextLoggerKey , contextLogger )
83
- r = r .WithContext (ctx )
60
+ // RequestLoggingWithFunc for WebHook
61
+ func RequestLoggingWithFunc (config * Config , w http.ResponseWriter , r * http.Request , next http.HandlerFunc ) {
62
+ reserve := NewReserve (config , r )
84
63
85
64
wrw := & wrappedResponseWriter {ResponseWriter : w }
86
65
defer func () {
87
66
// logging
88
- elapsed := time .Since (before )
89
- maxSeverity := contextLogger .maxSeverity ()
90
- err := writeRequestLog (r , config , wrw .status , wrw .responseSize , elapsed , traces , maxSeverity )
91
- if err != nil {
92
- _ , _ = fmt .Fprintln (os .Stderr , err .Error ())
93
- }
67
+ reserve .LastHandling (wrw )
94
68
}()
95
69
96
- return wrw , r
70
+ next . ServeHTTP ( w , reserve . request )
97
71
}
98
72
99
73
type Reserve struct {
0 commit comments