|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +import arrify = require('arrify'); |
17 | 18 | import {DeleteCallback} from '@google-cloud/common'; |
18 | 19 | import {callbackifyAll} from '@google-cloud/promisify'; |
19 | | -import arrify = require('arrify'); |
| 20 | +import * as dotProp from 'dot-prop'; |
20 | 21 | import * as extend from 'extend'; |
21 | 22 | import {CallOptions} from 'google-gax'; |
22 | 23 | import {Response} from 'teeny-request'; |
@@ -886,27 +887,33 @@ class Log implements LogSeverityFunctions { |
886 | 887 | const payloadSize = JSON.stringify(entry).length; |
887 | 888 | if (payloadSize < this.maxEntrySize) return; |
888 | 889 |
|
889 | | - const delta = payloadSize - this.maxEntrySize; |
| 890 | + let delta = payloadSize - this.maxEntrySize; |
890 | 891 | if (entry.textPayload) { |
891 | 892 | entry.textPayload = entry.textPayload.slice( |
892 | 893 | 0, |
893 | 894 | Math.max(entry.textPayload.length - delta, 0) |
894 | 895 | ); |
895 | 896 | } else { |
896 | | - // Stackdriver Log Viewer picks up the summary line from the |
897 | | - // 'message' field. |
898 | | - if ( |
899 | | - entry.jsonPayload && |
900 | | - entry.jsonPayload.fields && |
901 | | - entry.jsonPayload.fields.message && |
902 | | - entry.jsonPayload.fields.message.stringValue |
903 | | - ) { |
904 | | - const text: string | null | undefined = |
905 | | - entry.jsonPayload.fields.message.stringValue; |
906 | | - entry.jsonPayload.fields.message.stringValue = text.slice( |
907 | | - 0, |
908 | | - Math.max(text.length - delta, 0) |
909 | | - ); |
| 897 | + const fieldsToTruncate = [ |
| 898 | + // Winston: |
| 899 | + 'jsonPayload.fields.metadata.structValue.fields.stack.stringValue', |
| 900 | + // Bunyan: |
| 901 | + 'jsonPayload.fields.msg.stringValue', |
| 902 | + 'jsonPayload.fields.err.structValue.fields.stack.stringValue', |
| 903 | + 'jsonPayload.fields.err.structValue.fields.message.stringValue', |
| 904 | + // All: |
| 905 | + 'jsonPayload.fields.message.stringValue', |
| 906 | + ]; |
| 907 | + for (const field of fieldsToTruncate) { |
| 908 | + const msg: string = dotProp.get(entry, field, ''); |
| 909 | + if (msg !== '') { |
| 910 | + dotProp.set( |
| 911 | + entry, |
| 912 | + field, |
| 913 | + msg.slice(0, Math.max(msg.length - delta, 0)) |
| 914 | + ); |
| 915 | + delta -= Math.min(msg.length, delta); |
| 916 | + } |
910 | 917 | } |
911 | 918 | } |
912 | 919 | }); |
|
0 commit comments