@google-cloud/logging
Advanced tools
Comparing version 9.0.2 to 9.1.0
@@ -26,3 +26,3 @@ /*! | ||
import { Entry, LogEntry } from './entry'; | ||
import { Log, GetEntriesRequest, LogOptions, MonitoredResource, Severity, SeverityNames } from './log'; | ||
import { Log, GetEntriesRequest, TailEntriesRequest, LogOptions, MonitoredResource, Severity, SeverityNames } from './log'; | ||
import { Sink } from './sink'; | ||
@@ -60,2 +60,6 @@ import { Duplex } from 'stream'; | ||
} | ||
export interface TailEntriesResponse { | ||
entries: Entry[]; | ||
suppressionInfo: google.logging.v2.TailLogEntriesResponse.SuppressionInfo; | ||
} | ||
export interface GetLogsRequest { | ||
@@ -269,2 +273,35 @@ autoPaginate?: boolean; | ||
getEntriesStream(options?: GetEntriesRequest): Duplex; | ||
/** | ||
* Streaming read of live logs as log entries are ingested. Until the stream | ||
* is terminated, it will continue reading logs. | ||
* | ||
* @method Logging#tailEntries | ||
* @param {TailEntriesRequest} [query] Query object for tailing entries. | ||
* @returns {DuplexStream} A duplex stream that emits TailEntriesResponses | ||
* containing an array of {@link Entry} instances. | ||
* | ||
* @example | ||
* const {Logging} = require('@google-cloud/logging'); | ||
* const logging = new Logging(); | ||
* | ||
* logging.tailEntries() | ||
* .on('error', console.error) | ||
* .on('data', resp => { | ||
* console.log(resp.entries); | ||
* console.log(resp.suppressionInfo); | ||
* }) | ||
* .on('end', function() { | ||
* // All entries retrieved. | ||
* }); | ||
* | ||
* //- | ||
* // If you anticipate many results, you can end a stream early to prevent | ||
* // unnecessary processing and API requests. | ||
* //- | ||
* logging.getEntriesStream() | ||
* .on('data', function(entry) { | ||
* this.end(); | ||
* }); | ||
*/ | ||
tailEntries(options?: TailEntriesRequest): Duplex; | ||
getLogs(options?: GetLogsRequest): Promise<GetLogsResponse>; | ||
@@ -271,0 +308,0 @@ getLogs(callback: GetLogsCallback): void; |
@@ -505,2 +505,84 @@ "use strict"; | ||
/** | ||
* Streaming read of live logs as log entries are ingested. Until the stream | ||
* is terminated, it will continue reading logs. | ||
* | ||
* @method Logging#tailEntries | ||
* @param {TailEntriesRequest} [query] Query object for tailing entries. | ||
* @returns {DuplexStream} A duplex stream that emits TailEntriesResponses | ||
* containing an array of {@link Entry} instances. | ||
* | ||
* @example | ||
* const {Logging} = require('@google-cloud/logging'); | ||
* const logging = new Logging(); | ||
* | ||
* logging.tailEntries() | ||
* .on('error', console.error) | ||
* .on('data', resp => { | ||
* console.log(resp.entries); | ||
* console.log(resp.suppressionInfo); | ||
* }) | ||
* .on('end', function() { | ||
* // All entries retrieved. | ||
* }); | ||
* | ||
* //- | ||
* // If you anticipate many results, you can end a stream early to prevent | ||
* // unnecessary processing and API requests. | ||
* //- | ||
* logging.getEntriesStream() | ||
* .on('data', function(entry) { | ||
* this.end(); | ||
* }); | ||
*/ | ||
tailEntries(options = {}) { | ||
const userStream = streamEvents(pumpify.obj()); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let gaxStream; | ||
userStream.abort = () => { | ||
if (gaxStream && gaxStream.cancel) { | ||
gaxStream.cancel(); | ||
} | ||
}; | ||
const transformStream = through.obj((data, _, next) => { | ||
next(null, (() => { | ||
const formattedEntries = []; | ||
data.entries.forEach((entry) => { | ||
formattedEntries.push(entry_1.Entry.fromApiResponse_(entry)); | ||
}); | ||
const resp = { | ||
entries: formattedEntries, | ||
suppressionInfo: data.suppressionInfo, | ||
}; | ||
return resp; | ||
})()); | ||
}); | ||
this.auth.getProjectId().then(projectId => { | ||
this.projectId = projectId; | ||
if (options.log) { | ||
if (options.filter) { | ||
options.filter = `(${options.filter}) AND logName="${log_1.Log.formatName_(this.projectId, options.log)}"`; | ||
} | ||
else { | ||
options.filter = `logName="${log_1.Log.formatName_(this.projectId, options.log)}"`; | ||
} | ||
} | ||
options.resourceNames = arrify(options.resourceNames); | ||
options.resourceNames.push(`projects/${this.projectId}`); | ||
const writeOptions = { | ||
resourceNames: options.resourceNames, | ||
...(options.filter && { filter: options.filter }), | ||
...(options.bufferWindow && { bufferwindow: options.bufferWindow }), | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
if (!global.GCLOUD_SANDBOX_ENV) { | ||
gaxStream = this.loggingService.tailLogEntries(options.gaxOptions); | ||
// Write can only be called once in a single tail streaming session. | ||
gaxStream.write(writeOptions); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
userStream.setPipeline(gaxStream, transformStream); | ||
} | ||
}); | ||
return userStream; | ||
} | ||
/** | ||
* Query object for listing entries. | ||
@@ -507,0 +589,0 @@ * |
@@ -33,2 +33,9 @@ /*! | ||
} | ||
export interface TailEntriesRequest { | ||
resourceNames?: string[] | string; | ||
filter?: string; | ||
bufferWindow?: number; | ||
log?: string; | ||
gaxOptions?: CallOptions; | ||
} | ||
export interface LogOptions { | ||
@@ -155,2 +162,37 @@ removeCircular?: boolean; | ||
getEntriesStream(options: GetEntriesRequest): import("stream").Duplex; | ||
/** | ||
* This method is a wrapper around {module:logging#tailEntries}, but with | ||
* a filter specified to only return {module:logging/entry} objects from this | ||
* log. | ||
* | ||
* @method Log#tailEntries | ||
* @param {TailEntriesRequest} [query] Query object for tailing entries. | ||
* @returns {DuplexStream} A duplex stream that emits TailEntriesResponses | ||
* containing an array of {@link Entry} instances. | ||
* | ||
* @example | ||
* const {Logging} = require('@google-cloud/logging'); | ||
* const logging = new Logging(); | ||
* const log = logging.log('my-log'); | ||
* | ||
* log.tailEntries() | ||
* .on('error', console.error) | ||
* .on('data', resp => { | ||
* console.log(resp.entries); | ||
* console.log(resp.suppressionInfo); | ||
* }) | ||
* .on('end', function() { | ||
* // All entries retrieved. | ||
* }); | ||
* | ||
* //- | ||
* // If you anticipate many results, you can end a stream early to prevent | ||
* // unnecessary processing and API requests. | ||
* //- | ||
* log.tailEntries() | ||
* .on('data', function(entry) { | ||
* this.end(); | ||
* }); | ||
*/ | ||
tailEntries(options?: TailEntriesRequest): import("stream").Duplex; | ||
info(entry: Entry | Entry[], options?: WriteOptions): Promise<ApiResponse>; | ||
@@ -157,0 +199,0 @@ info(entry: Entry | Entry[], options: WriteOptions, callback: ApiResponseCallback): void; |
@@ -445,2 +445,42 @@ "use strict"; | ||
/** | ||
* This method is a wrapper around {module:logging#tailEntries}, but with | ||
* a filter specified to only return {module:logging/entry} objects from this | ||
* log. | ||
* | ||
* @method Log#tailEntries | ||
* @param {TailEntriesRequest} [query] Query object for tailing entries. | ||
* @returns {DuplexStream} A duplex stream that emits TailEntriesResponses | ||
* containing an array of {@link Entry} instances. | ||
* | ||
* @example | ||
* const {Logging} = require('@google-cloud/logging'); | ||
* const logging = new Logging(); | ||
* const log = logging.log('my-log'); | ||
* | ||
* log.tailEntries() | ||
* .on('error', console.error) | ||
* .on('data', resp => { | ||
* console.log(resp.entries); | ||
* console.log(resp.suppressionInfo); | ||
* }) | ||
* .on('end', function() { | ||
* // All entries retrieved. | ||
* }); | ||
* | ||
* //- | ||
* // If you anticipate many results, you can end a stream early to prevent | ||
* // unnecessary processing and API requests. | ||
* //- | ||
* log.tailEntries() | ||
* .on('data', function(entry) { | ||
* this.end(); | ||
* }); | ||
*/ | ||
tailEntries(options) { | ||
options = extend({ | ||
log: this.name, | ||
}, options); | ||
return this.logging.tailEntries(options); | ||
} | ||
/** | ||
* Write a log entry with a severity of "INFO". | ||
@@ -447,0 +487,0 @@ * |
@@ -7,2 +7,14 @@ # Changelog | ||
## [9.1.0](https://www.github.com/googleapis/nodejs-logging/compare/v9.0.2...v9.1.0) (2021-03-03) | ||
### Features | ||
* tail entries wrapper ([#998](https://www.github.com/googleapis/nodejs-logging/issues/998)) ([bfe8b76](https://www.github.com/googleapis/nodejs-logging/commit/bfe8b765d1c690e81c96f0c71e4e431622f67104)) | ||
### Bug Fixes | ||
* **deps:** update dependency type-fest to ^0.21.0 ([#997](https://www.github.com/googleapis/nodejs-logging/issues/997)) ([47a4c72](https://www.github.com/googleapis/nodejs-logging/commit/47a4c724f4f359f9c3d05360881724cbb14894d7)) | ||
### [9.0.2](https://www.github.com/googleapis/nodejs-logging/compare/v9.0.1...v9.0.2) (2021-02-09) | ||
@@ -9,0 +21,0 @@ |
{ | ||
"name": "@google-cloud/logging", | ||
"version": "9.0.2", | ||
"version": "9.1.0", | ||
"description": "Stackdriver Logging Client Library for Node.js", | ||
@@ -67,3 +67,3 @@ "keywords": [ | ||
"through2": "^4.0.0", | ||
"type-fest": "^0.20.0" | ||
"type-fest": "^0.21.0" | ||
}, | ||
@@ -70,0 +70,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
3519522
59034
+ Addedtype-fest@0.21.3(transitive)
- Removedtype-fest@0.20.2(transitive)
Updatedtype-fest@^0.21.0