diff --git a/cmd/sst/mosaic/aws/aws.go b/cmd/sst/mosaic/aws/aws.go index ad8780502..94b46ff37 100644 --- a/cmd/sst/mosaic/aws/aws.go +++ b/cmd/sst/mosaic/aws/aws.go @@ -14,6 +14,7 @@ import ( "net/http" "net/url" "os" + "path/filepath" "strconv" "strings" "sync" @@ -230,11 +231,13 @@ func Start( evts := bus.Subscribe(&FunctionLogEvent{}, &FunctionInvokedEvent{}, &FunctionResponseEvent{}, &FunctionErrorEvent{}, &FunctionBuildEvent{}) logs := map[string]*os.File{} - getLog := func(functionID string) *os.File { - log, ok := logs[functionID] + getLog := func(functionID string, requestID string) *os.File { + log, ok := logs[requestID] if !ok { - log, _ = os.Create(p.PathLog("lambda-" + functionID)) - logs[functionID] = log + path := p.PathLog("lambda/" + functionID + "/" + requestID) + os.MkdirAll(filepath.Dir(path), 0755) + log, _ = os.Create(path) + logs[requestID] = log } return log } @@ -243,15 +246,21 @@ func Start( for evt := range evts { switch evt := evt.(type) { case *FunctionInvokedEvent: - getLog(evt.FunctionID).WriteString("invocation " + evt.RequestID + "\n") + log := getLog(evt.FunctionID, evt.RequestID) + log.WriteString("invocation " + evt.RequestID + "\n") + log.WriteString(string(evt.Input)) + log.WriteString("\n") case *FunctionLogEvent: - getLog(evt.FunctionID).WriteString(evt.Line + "\n") + getLog(evt.FunctionID, evt.RequestID).WriteString(evt.Line + "\n") case *FunctionResponseEvent: - getLog(evt.FunctionID).WriteString("response " + evt.RequestID + "\n") + log := getLog(evt.FunctionID, evt.RequestID) + log.WriteString("response " + evt.RequestID + "\n") + log.WriteString(string(evt.Output)) + log.WriteString("\n") + delete(logs, evt.RequestID) case *FunctionErrorEvent: - getLog(evt.FunctionID).WriteString(evt.ErrorType + ": " + evt.ErrorMessage + "\n") - case *FunctionBuildEvent: - getLog(evt.FunctionID).WriteString(evt.Errors[0] + "\n") + getLog(evt.FunctionID, evt.RequestID).WriteString(evt.ErrorType + ": " + evt.ErrorMessage + "\n") + delete(logs, evt.RequestID) } } }