(chunk, encoding, callback)
| 14 | const writeable = new Writable({ |
| 15 | defaultEncoding: 'utf8', |
| 16 | write(chunk, encoding, callback) { |
| 17 | const storageProvider = options.storageProvider || GlobalContextStorageProvider; |
| 18 | const formatter = options.formatter || new CloudwatchLogFormatter(); |
| 19 | |
| 20 | const data = JSON.parse(chunk); |
| 21 | const lambdaContext = storageProvider.getContext() || {}; |
| 22 | |
| 23 | // format the combined request context and log data |
| 24 | let output = formatter.format({ ...lambdaContext, ...data }); |
| 25 | |
| 26 | // replace characters for proper formatting |
| 27 | output = output.replace(/\n/, '\r'); |
| 28 | |
| 29 | // final entry must end with carriage return |
| 30 | output += '\n'; |
| 31 | |
| 32 | /* istanbul ignore else */ |
| 33 | if (options.streamWriter) { |
| 34 | options.streamWriter(output); |
| 35 | } else { |
| 36 | process.stdout.write(output); |
| 37 | } |
| 38 | |
| 39 | callback(); |
| 40 | }, |
| 41 | }); |
| 42 | |
| 43 | return writeable; |
nothing calls this directly
no test coverage detected
searching dependent graphs…