@google-cloud/logging
Advanced tools
Comparing version 9.6.6 to 9.6.7
@@ -48,2 +48,3 @@ /*! | ||
maxEntrySize?: number; | ||
jsonFieldsToTruncate?: string[]; | ||
} | ||
@@ -73,2 +74,4 @@ export declare type Metadata = any; | ||
* @param {number} [options.maxEntrySize] A max entry size | ||
* @param {string[]} [options.jsonFieldsToTruncate] A list of JSON properties at the given full path to be truncated. | ||
* Received values will be prepended to predefined list in the order received and duplicates discarded. | ||
* | ||
@@ -88,2 +91,3 @@ * @example | ||
name: string; | ||
jsonFieldsToTruncate: string[]; | ||
constructor(logging: Logging, name: string, options?: LogOptions); | ||
@@ -90,0 +94,0 @@ /** |
@@ -42,2 +42,4 @@ "use strict"; | ||
* @param {number} [options.maxEntrySize] A max entry size | ||
* @param {string[]} [options.jsonFieldsToTruncate] A list of JSON properties at the given full path to be truncated. | ||
* Received values will be prepended to predefined list in the order received and duplicates discarded. | ||
* | ||
@@ -63,2 +65,23 @@ * @example | ||
this.name = this.formattedName_.split('/').pop(); | ||
this.jsonFieldsToTruncate = [ | ||
// Winston: | ||
'jsonPayload.fields.metadata.structValue.fields.stack.stringValue', | ||
// Bunyan: | ||
'jsonPayload.fields.msg.stringValue', | ||
'jsonPayload.fields.err.structValue.fields.stack.stringValue', | ||
'jsonPayload.fields.err.structValue.fields.message.stringValue', | ||
// All: | ||
'jsonPayload.fields.message.stringValue', | ||
]; | ||
// Prepend all custom fields to be truncated to a list with defaults, thus | ||
// custom fields will be truncated first. Make sure to filter out fields | ||
// which are not in EntryJson.jsonPayload | ||
if (options.jsonFieldsToTruncate !== null && | ||
options.jsonFieldsToTruncate !== undefined) { | ||
const filteredList = options.jsonFieldsToTruncate.filter(str => str !== null && | ||
!this.jsonFieldsToTruncate.includes(str) && | ||
str.startsWith('jsonPayload')); | ||
const uniqueSet = new Set(filteredList); | ||
this.jsonFieldsToTruncate = Array.from(uniqueSet).concat(this.jsonFieldsToTruncate); | ||
} | ||
} | ||
@@ -291,17 +314,10 @@ alert(entry, options) { | ||
else { | ||
const fieldsToTruncate = [ | ||
// Winston: | ||
'jsonPayload.fields.metadata.structValue.fields.stack.stringValue', | ||
// Bunyan: | ||
'jsonPayload.fields.msg.stringValue', | ||
'jsonPayload.fields.err.structValue.fields.stack.stringValue', | ||
'jsonPayload.fields.err.structValue.fields.message.stringValue', | ||
// All: | ||
'jsonPayload.fields.message.stringValue', | ||
]; | ||
for (const field of fieldsToTruncate) { | ||
for (const field of this.jsonFieldsToTruncate) { | ||
const msg = dotProp.get(entry, field, ''); | ||
if (msg !== '') { | ||
if (msg !== null && msg !== undefined && msg !== '') { | ||
dotProp.set(entry, field, msg.slice(0, Math.max(msg.length - delta, 0))); | ||
delta -= Math.min(msg.length, delta); | ||
if (delta <= 0) { | ||
break; | ||
} | ||
} | ||
@@ -308,0 +324,0 @@ } |
@@ -7,2 +7,9 @@ # Changelog | ||
### [9.6.7](https://github.com/googleapis/nodejs-logging/compare/v9.6.6...v9.6.7) (2022-01-11) | ||
### Bug Fixes | ||
* Setting maxEntrySize does not truncate big json payloads correctly ([#1177](https://github.com/googleapis/nodejs-logging/issues/1177)) ([ec66e4d](https://github.com/googleapis/nodejs-logging/commit/ec66e4dc96a89259852688d395e647e9a019089d)) | ||
### [9.6.6](https://www.github.com/googleapis/nodejs-logging/compare/v9.6.5...v9.6.6) (2021-12-22) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/logging", | ||
"version": "9.6.6", | ||
"version": "9.6.7", | ||
"description": "Stackdriver Logging Client Library for Node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -9,3 +9,2 @@ [//]: # "This README.md file is auto-generated, all changes to this file will be lost." | ||
[![npm version](https://img.shields.io/npm/v/@google-cloud/logging.svg)](https://www.npmjs.org/package/@google-cloud/logging) | ||
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-logging/main.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-logging) | ||
@@ -221,2 +220,4 @@ | ||
More Information: [Google Cloud Platform Launch Stages][launch_stages] | ||
@@ -223,0 +224,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3606630
60618
248