( data: Uint8Array | string, encoding?: BufferEncoding, stderr = false, )
| 107 | } |
| 108 | |
| 109 | export function getModifiedData( |
| 110 | data: Uint8Array | string, |
| 111 | encoding?: BufferEncoding, |
| 112 | stderr = false, |
| 113 | ) { |
| 114 | const currentContext = getCurrentContext(); |
| 115 | if (!currentContext) { |
| 116 | return data; |
| 117 | } |
| 118 | const {isJSON, processedData} = processData(data, encoding); |
| 119 | |
| 120 | let dataWithContext: { |
| 121 | message: string | Uint8Array; |
| 122 | 'logging.googleapis.com/labels': {execution_id: string | undefined}; |
| 123 | 'logging.googleapis.com/spanId': string | undefined; |
| 124 | severity?: string | undefined; |
| 125 | }; |
| 126 | if (isJSON) { |
| 127 | dataWithContext = getJSONWithContext(processedData, currentContext); |
| 128 | if (stderr && !(SEVERITY in dataWithContext)) { |
| 129 | dataWithContext[SEVERITY] = 'ERROR'; |
| 130 | } |
| 131 | } else { |
| 132 | dataWithContext = getTextWithContext(processedData, currentContext); |
| 133 | } |
| 134 | |
| 135 | return JSON.stringify(dataWithContext) + '\n'; |
| 136 | } |
| 137 | |
| 138 | function getTextWithContext( |
| 139 | data: Uint8Array | string, |
no test coverage detected