Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 8944236

Browse files
committed
sst.aws.Function: fix log issue
1 parent 64f15ea commit 8944236

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

cmd/sst/mosaic/aws/aws.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"net/http"
1515
"net/url"
1616
"os"
17+
"path/filepath"
1718
"strconv"
1819
"strings"
1920
"sync"
@@ -230,11 +231,13 @@ func Start(
230231
evts := bus.Subscribe(&FunctionLogEvent{}, &FunctionInvokedEvent{}, &FunctionResponseEvent{}, &FunctionErrorEvent{}, &FunctionBuildEvent{})
231232
logs := map[string]*os.File{}
232233

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]
235236
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
238241
}
239242
return log
240243
}
@@ -243,15 +246,21 @@ func Start(
243246
for evt := range evts {
244247
switch evt := evt.(type) {
245248
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")
247253
case *FunctionLogEvent:
248-
getLog(evt.FunctionID).WriteString(evt.Line + "\n")
254+
getLog(evt.FunctionID, evt.RequestID).WriteString(evt.Line + "\n")
249255
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)
251261
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)
255264
}
256265
}
257266
}

0 commit comments

Comments
 (0)