@@ -14,6 +14,7 @@ import (
14
14
"net/http"
15
15
"net/url"
16
16
"os"
17
+ "path/filepath"
17
18
"strconv"
18
19
"strings"
19
20
"sync"
@@ -230,11 +231,13 @@ func Start(
230
231
evts := bus .Subscribe (& FunctionLogEvent {}, & FunctionInvokedEvent {}, & FunctionResponseEvent {}, & FunctionErrorEvent {}, & FunctionBuildEvent {})
231
232
logs := map [string ]* os.File {}
232
233
233
- getLog := func (functionID string ) * os.File {
234
- log , ok := logs [functionID ]
234
+ getLog := func (functionID string , requestID string ) * os.File {
235
+ log , ok := logs [requestID ]
235
236
if ! ok {
236
- log , _ = os .Create (p .PathLog ("lambda-" + functionID ))
237
- logs [functionID ] = log
237
+ path := p .PathLog ("lambda/" + functionID + "/" + requestID )
238
+ os .MkdirAll (filepath .Dir (path ), 0755 )
239
+ log , _ = os .Create (path )
240
+ logs [requestID ] = log
238
241
}
239
242
return log
240
243
}
@@ -243,15 +246,21 @@ func Start(
243
246
for evt := range evts {
244
247
switch evt := evt .(type ) {
245
248
case * FunctionInvokedEvent :
246
- getLog (evt .FunctionID ).WriteString ("invocation " + evt .RequestID + "\n " )
249
+ log := getLog (evt .FunctionID , evt .RequestID )
250
+ log .WriteString ("invocation " + evt .RequestID + "\n " )
251
+ log .WriteString (string (evt .Input ))
252
+ log .WriteString ("\n " )
247
253
case * FunctionLogEvent :
248
- getLog (evt .FunctionID ).WriteString (evt .Line + "\n " )
254
+ getLog (evt .FunctionID , evt . RequestID ).WriteString (evt .Line + "\n " )
249
255
case * FunctionResponseEvent :
250
- getLog (evt .FunctionID ).WriteString ("response " + evt .RequestID + "\n " )
256
+ log := getLog (evt .FunctionID , evt .RequestID )
257
+ log .WriteString ("response " + evt .RequestID + "\n " )
258
+ log .WriteString (string (evt .Output ))
259
+ log .WriteString ("\n " )
260
+ delete (logs , evt .RequestID )
251
261
case * FunctionErrorEvent :
252
- getLog (evt .FunctionID ).WriteString (evt .ErrorType + ": " + evt .ErrorMessage + "\n " )
253
- case * FunctionBuildEvent :
254
- getLog (evt .FunctionID ).WriteString (evt .Errors [0 ] + "\n " )
262
+ getLog (evt .FunctionID , evt .RequestID ).WriteString (evt .ErrorType + ": " + evt .ErrorMessage + "\n " )
263
+ delete (logs , evt .RequestID )
255
264
}
256
265
}
257
266
}
0 commit comments