File tree Expand file tree Collapse file tree
Sources/AWSLambdaRuntime/Logging
Tests/AWSLambdaRuntimeTests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616import Logging
1717
1818#if canImport(Darwin)
19- import Darwin. C
19+ import Darwin
2020#elseif canImport(Glibc)
2121import Glibc
2222#elseif canImport(Musl)
@@ -169,7 +169,10 @@ public struct JSONLogHandler: LogHandler {
169169 /// Returns nil if encoding fails.
170170 internal static func encodeLogEntry( _ logEntry: LogEntry ) -> Data ? {
171171 let encoder = JSONEncoder ( )
172- encoder. dateEncodingStrategy = . iso8601
172+ encoder. dateEncodingStrategy = . custom { date, encoder in
173+ var container = encoder. singleValueContainer ( )
174+ try container. encode ( date. formatted ( Date . ISO8601FormatStyle ( includingFractionalSeconds: true ) ) )
175+ }
173176 encoder. outputFormatting = [ ] // Compact output (no pretty printing)
174177 return try ? encoder. encode ( logEntry)
175178 }
Original file line number Diff line number Diff line change @@ -183,10 +183,10 @@ struct JSONLogHandlerTests {
183183 let timestamp = entry? . timestamp
184184 #expect( timestamp != nil )
185185
186- // Verify it matches ISO 8601 format (e.g. "2024-01-16T10:30:45Z ")
187- let iso8601Pattern = #"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}( \.\\d+)? Z$"#
186+ // Verify it matches ISO 8601 format with milliseconds (e.g. "2024-01-16T10:30:45.123Z ")
187+ let iso8601Pattern = #"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,6} Z$"#
188188 let matches = timestamp? . range ( of: iso8601Pattern, options: . regularExpression) != nil
189- #expect( matches, " Timestamp ' \( timestamp ?? " " ) ' should be in ISO 8601 format " )
189+ #expect( matches, " Timestamp ' \( timestamp ?? " " ) ' should be in ISO 8601 format with fractional seconds " )
190190 }
191191
192192 // MARK: - Metadata subscript
You can’t perform that action at this time.
0 commit comments