@google-cloud/logging
Advanced tools
Comparing version 5.4.1 to 5.5.0
@@ -22,3 +22,3 @@ /*! | ||
import { GetEntriesCallback, GetEntriesResponse, Logging } from '.'; | ||
import { Entry, LogEntry } from './entry'; | ||
import { Entry, EntryJson, LogEntry } from './entry'; | ||
export interface GetEntriesRequest { | ||
@@ -38,2 +38,3 @@ autoPaginate?: boolean; | ||
removeCircular?: boolean; | ||
maxEntrySize?: number; | ||
} | ||
@@ -91,2 +92,3 @@ export declare type ApiResponse = [Response]; | ||
removeCircular_: boolean; | ||
maxEntrySize?: number; | ||
logging: Logging; | ||
@@ -622,4 +624,14 @@ name: string; | ||
*/ | ||
decorateEntries_(entries: Entry[]): import("./entry").EntryJson[]; | ||
decorateEntries_(entries: Entry[]): EntryJson[]; | ||
/** | ||
* Truncate log entries at maxEntrySize, so that error is not thrown, see: | ||
* https://cloud.google.com/logging/quotas | ||
* | ||
* @private | ||
* | ||
* @param {object|string} the JSON log entry. | ||
* @returns {object|string} truncated JSON log entry. | ||
*/ | ||
private truncateEntries; | ||
/** | ||
* Return an array of log entries with the desired severity assigned. | ||
@@ -626,0 +638,0 @@ * |
@@ -62,2 +62,3 @@ "use strict"; | ||
this.removeCircular_ = options.removeCircular === true; | ||
this.maxEntrySize = options.maxEntrySize; | ||
this.logging = logging; | ||
@@ -190,2 +191,3 @@ /** | ||
} | ||
self.truncateEntries(decoratedEntries); | ||
const projectId = await self.logging.auth.getProjectId(); | ||
@@ -222,2 +224,35 @@ self.formattedName_ = Log.formatName_(projectId, self.name); | ||
/** | ||
* Truncate log entries at maxEntrySize, so that error is not thrown, see: | ||
* https://cloud.google.com/logging/quotas | ||
* | ||
* @private | ||
* | ||
* @param {object|string} the JSON log entry. | ||
* @returns {object|string} truncated JSON log entry. | ||
*/ | ||
truncateEntries(entries) { | ||
return entries.forEach(entry => { | ||
if (this.maxEntrySize === undefined) | ||
return; | ||
const payloadSize = JSON.stringify(entry).length; | ||
if (payloadSize < this.maxEntrySize) | ||
return; | ||
const delta = payloadSize - this.maxEntrySize; | ||
if (entry.textPayload) { | ||
entry.textPayload = entry.textPayload.slice(0, Math.max(entry.textPayload.length - delta, 0)); | ||
} | ||
else { | ||
// Stackdriver Log Viewer picks up the summary line from the | ||
// 'message' field. | ||
if (entry.jsonPayload && | ||
entry.jsonPayload.fields && | ||
entry.jsonPayload.fields.message && | ||
entry.jsonPayload.fields.message.stringValue) { | ||
const text = entry.jsonPayload.fields.message.stringValue; | ||
entry.jsonPayload.fields.message.stringValue = text.slice(0, Math.max(text.length - delta, 0)); | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
* Return an array of log entries with the desired severity assigned. | ||
@@ -224,0 +259,0 @@ * |
@@ -7,2 +7,9 @@ # Changelog | ||
## [5.5.0](https://www.github.com/googleapis/nodejs-logging/compare/v5.4.1...v5.5.0) (2019-10-16) | ||
### Features | ||
* introduce maxEntrySize, for enabling error message truncation ([#607](https://www.github.com/googleapis/nodejs-logging/issues/607)) ([49efd49](https://www.github.com/googleapis/nodejs-logging/commit/49efd491263b518ae5cd54c9a77e5603477f96d8)) | ||
### [5.4.1](https://www.github.com/googleapis/nodejs-logging/compare/v5.4.0...v5.4.1) (2019-10-10) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/logging", | ||
"description": "Stackdriver Logging Client Library for Node.js", | ||
"version": "5.4.1", | ||
"version": "5.5.0", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google Inc.", |
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
3312732
60961