@google-cloud/logging-min
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 @@ /** |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.Log=void 0;const arrify=require("arrify");const promisify_1=require("@google-cloud/promisify");const dotProp=require("dot-prop");const extend=require("extend");const entry_1=require("./entry");const log_common_1=require("./utils/log-common");class Log{constructor(logging,name,options){options=options||{};this.formattedName_=log_common_1.formatLogName(logging.projectId,name);this.removeCircular_=options.removeCircular===true;this.maxEntrySize=options.maxEntrySize;this.logging=logging;this.name=this.formattedName_.split("/").pop()}alert(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"ALERT"),options)}critical(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"CRITICAL"),options)}debug(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"DEBUG"),options)}async delete(gaxOptions){const projectId=await this.logging.auth.getProjectId();this.formattedName_=log_common_1.formatLogName(projectId,this.name);const reqOpts={logName:this.formattedName_};return this.logging.loggingService.deleteLog(reqOpts,gaxOptions)}emergency(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"EMERGENCY"),options)}entry(metadataOrData,data){let metadata;if(!data&&(metadataOrData===null||metadataOrData===void 0?void 0:metadataOrData.hasOwnProperty("httpRequest"))){metadata=metadataOrData;data={}}else if(!data){data=metadataOrData;metadata={}}else{metadata=metadataOrData}return this.logging.entry(metadata,data)}error(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"ERROR"),options)}async getEntries(opts){const options=extend({},opts);const projectId=await this.logging.auth.getProjectId();this.formattedName_=log_common_1.formatLogName(projectId,this.name);if(options.filter&&!options.filter.includes("logName=")){options.filter=`(${options.filter}) AND logName="${this.formattedName_}"`}else if(!options.filter){options.filter=`logName="${this.formattedName_}"`}return this.logging.getEntries(options)}getEntriesStream(options){options=extend({log:this.name},options);return this.logging.getEntriesStream(options)}tailEntries(options){options=extend({log:this.name},options);return this.logging.tailEntries(options)}info(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"INFO"),options)}notice(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"NOTICE"),options)}warning(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"WARNING"),options)}async write(entry,opts){const options=opts?opts:{};await this.logging.setProjectId();this.formattedName_=log_common_1.formatLogName(this.logging.projectId,this.name);const resource=await this.getOrSetResource(options);const decoratedEntries=this.decorateEntries(arrify(entry));this.truncateEntries(decoratedEntries);const reqOpts=extend({logName:this.formattedName_,entries:decoratedEntries,resource:resource},options);delete reqOpts.gaxOptions;return this.logging.loggingService.writeLogEntries(reqOpts,options.gaxOptions)}async getOrSetResource(options){if(options.resource){if(options.resource.labels)log_common_1.snakecaseKeys(options.resource.labels);return options.resource}await this.logging.setDetectedResource();return this.logging.detectedResource}decorateEntries(entries){return entries.map(entry=>{if(!(entry instanceof entry_1.Entry)){entry=this.entry(entry)}return entry.toJSON({removeCircular:this.removeCircular_},this.logging.projectId)})}truncateEntries(entries){return entries.forEach(entry=>{if(this.maxEntrySize===undefined)return;const payloadSize=JSON.stringify(entry).length;if(payloadSize<this.maxEntrySize)return;let delta=payloadSize-this.maxEntrySize;if(entry.textPayload){entry.textPayload=entry.textPayload.slice(0,Math.max(entry.textPayload.length-delta,0))}else{const fieldsToTruncate=["jsonPayload.fields.metadata.structValue.fields.stack.stringValue","jsonPayload.fields.msg.stringValue","jsonPayload.fields.err.structValue.fields.stack.stringValue","jsonPayload.fields.err.structValue.fields.message.stringValue","jsonPayload.fields.message.stringValue"];for(const field of fieldsToTruncate){const msg=dotProp.get(entry,field,"");if(msg!==""){dotProp.set(entry,field,msg.slice(0,Math.max(msg.length-delta,0)));delta-=Math.min(msg.length,delta)}}}})}static assignSeverityToEntries_(entries,severity){return log_common_1.assignSeverityToEntries(entries,severity)}static formatName_(projectId,name){return log_common_1.formatLogName(projectId,name)}}exports.Log=Log;promisify_1.callbackifyAll(Log,{exclude:["entry","getEntriesStream"]}); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.Log=void 0;const arrify=require("arrify");const promisify_1=require("@google-cloud/promisify");const dotProp=require("dot-prop");const extend=require("extend");const entry_1=require("./entry");const log_common_1=require("./utils/log-common");class Log{constructor(logging,name,options){options=options||{};this.formattedName_=log_common_1.formatLogName(logging.projectId,name);this.removeCircular_=options.removeCircular===true;this.maxEntrySize=options.maxEntrySize;this.logging=logging;this.name=this.formattedName_.split("/").pop();this.jsonFieldsToTruncate=["jsonPayload.fields.metadata.structValue.fields.stack.stringValue","jsonPayload.fields.msg.stringValue","jsonPayload.fields.err.structValue.fields.stack.stringValue","jsonPayload.fields.err.structValue.fields.message.stringValue","jsonPayload.fields.message.stringValue"];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)}}alert(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"ALERT"),options)}critical(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"CRITICAL"),options)}debug(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"DEBUG"),options)}async delete(gaxOptions){const projectId=await this.logging.auth.getProjectId();this.formattedName_=log_common_1.formatLogName(projectId,this.name);const reqOpts={logName:this.formattedName_};return this.logging.loggingService.deleteLog(reqOpts,gaxOptions)}emergency(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"EMERGENCY"),options)}entry(metadataOrData,data){let metadata;if(!data&&(metadataOrData===null||metadataOrData===void 0?void 0:metadataOrData.hasOwnProperty("httpRequest"))){metadata=metadataOrData;data={}}else if(!data){data=metadataOrData;metadata={}}else{metadata=metadataOrData}return this.logging.entry(metadata,data)}error(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"ERROR"),options)}async getEntries(opts){const options=extend({},opts);const projectId=await this.logging.auth.getProjectId();this.formattedName_=log_common_1.formatLogName(projectId,this.name);if(options.filter&&!options.filter.includes("logName=")){options.filter=`(${options.filter}) AND logName="${this.formattedName_}"`}else if(!options.filter){options.filter=`logName="${this.formattedName_}"`}return this.logging.getEntries(options)}getEntriesStream(options){options=extend({log:this.name},options);return this.logging.getEntriesStream(options)}tailEntries(options){options=extend({log:this.name},options);return this.logging.tailEntries(options)}info(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"INFO"),options)}notice(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"NOTICE"),options)}warning(entry,options){return this.write(log_common_1.assignSeverityToEntries(entry,"WARNING"),options)}async write(entry,opts){const options=opts?opts:{};await this.logging.setProjectId();this.formattedName_=log_common_1.formatLogName(this.logging.projectId,this.name);const resource=await this.getOrSetResource(options);const decoratedEntries=this.decorateEntries(arrify(entry));this.truncateEntries(decoratedEntries);const reqOpts=extend({logName:this.formattedName_,entries:decoratedEntries,resource:resource},options);delete reqOpts.gaxOptions;return this.logging.loggingService.writeLogEntries(reqOpts,options.gaxOptions)}async getOrSetResource(options){if(options.resource){if(options.resource.labels)log_common_1.snakecaseKeys(options.resource.labels);return options.resource}await this.logging.setDetectedResource();return this.logging.detectedResource}decorateEntries(entries){return entries.map(entry=>{if(!(entry instanceof entry_1.Entry)){entry=this.entry(entry)}return entry.toJSON({removeCircular:this.removeCircular_},this.logging.projectId)})}truncateEntries(entries){return entries.forEach(entry=>{if(this.maxEntrySize===undefined)return;const payloadSize=JSON.stringify(entry).length;if(payloadSize<this.maxEntrySize)return;let delta=payloadSize-this.maxEntrySize;if(entry.textPayload){entry.textPayload=entry.textPayload.slice(0,Math.max(entry.textPayload.length-delta,0))}else{for(const field of this.jsonFieldsToTruncate){const msg=dotProp.get(entry,field,"");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}}}}})}static assignSeverityToEntries_(entries,severity){return log_common_1.assignSeverityToEntries(entries,severity)}static formatName_(projectId,name){return log_common_1.formatLogName(projectId,name)}}exports.Log=Log;promisify_1.callbackifyAll(Log,{exclude:["entry","getEntriesStream"]}); | ||
//# sourceMappingURL=log.js.map |
@@ -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-min", | ||
"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 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
2075431
22683
248