Skip to content

Commit 41e5a65

Browse files
joe4devclaude
andcommitted
fix(init): normalize bare CR to LF in captured logs
The runtime emits multi-line records (e.g. an unhandled-init traceback) as a single log frame with internal newlines replaced by bare carriage returns. AWS renders these back as line feeds, so convert bare CR to LF in the assembled log output while preserving genuine CRLF endings (which AWS keeps, e.g. the LAMBDA_WARNING line). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 72a8b9f commit 41e5a65

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

cmd/localstack/logs.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,17 @@ func (lc *LogCollector) reset() {
3838
func (lc *LogCollector) getLogs() lsapi.LogResponse {
3939
lc.mutex.Lock()
4040
defer lc.mutex.Unlock()
41+
logs := strings.Join(lc.RuntimeLogs, "")
42+
// The runtime emits multi-line records (e.g. an unhandled-init traceback) as a single log
43+
// frame with internal newlines replaced by bare carriage returns. AWS renders those back as
44+
// line feeds, so convert bare CR to LF while preserving genuine CRLF line endings (which AWS
45+
// keeps verbatim, e.g. the LAMBDA_WARNING line).
46+
const crlfPlaceholder = "\x00"
47+
logs = strings.ReplaceAll(logs, "\r\n", crlfPlaceholder)
48+
logs = strings.ReplaceAll(logs, "\r", "\n")
49+
logs = strings.ReplaceAll(logs, crlfPlaceholder, "\r\n")
4150
response := lsapi.LogResponse{
42-
Logs: strings.Join(lc.RuntimeLogs, ""),
51+
Logs: logs,
4352
}
4453
lc.RuntimeLogs = []string{}
4554
return response

0 commit comments

Comments
 (0)