diff --git a/src/index.ts b/src/index.ts index eb0ccd16c..9a9ff9998 100644 --- a/src/index.ts +++ b/src/index.ts @@ -433,6 +433,8 @@ class Logging { * empty filter matches all log entries. * @property {object} [gaxOptions] Request configuration options, outlined * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions. + * @property {string} [log] A name of the log specifying to pnly return + * entries from this log. * @property {number} [maxApiCalls] Maximum number of API calls to make. * @property {number} [maxResults] Maximum number of items plus prefixes to * return. @@ -580,10 +582,14 @@ class Logging { userStream.once('reading', () => { this.auth.getProjectId().then(projectId => { this.projectId = projectId; - if (options.logName_) { - options.filter = - `logName="${Log.formatName_(this.projectId, options.logName_)}"`; - delete options.logName_; + if (options.log) { + options = extend( + { + filter: + `logName="${Log.formatName_(this.projectId, options.log)}"`, + }, + options); + delete options.log; } const reqOpts = extend( { diff --git a/src/log.ts b/src/log.ts index d354206f8..cd9f7fe28 100644 --- a/src/log.ts +++ b/src/log.ts @@ -33,13 +33,13 @@ export interface GetEntriesRequest { autoPaginate?: boolean; filter?: string; gaxOptions?: CallOptions; + log?: string; maxApiCalls?: number; maxResults?: number; orderBy?: string; pageSize?: number; pageToken?: string; resourceNames?: string[]|string; - logName_?: string; } export interface LogOptions { @@ -563,7 +563,7 @@ class Log implements LogSeverityFunctions { getEntriesStream(options: GetEntriesRequest) { options = extend( { - logName_: this.name, + log: this.name, }, options); return this.logging.getEntriesStream(options); diff --git a/test/index.ts b/test/index.ts index b02d1fa11..c20c703f0 100644 --- a/test/index.ts +++ b/test/index.ts @@ -21,6 +21,7 @@ import * as assert from 'assert'; import * as extend from 'extend'; import * as proxyquire from 'proxyquire'; import * as through from 'through2'; +import {Logging as LOGGING} from '../src/index'; import {GetEntriesCallback} from '../src/index'; import {getOrInjectContext} from '../src/middleware/context'; @@ -98,6 +99,7 @@ class FakeLog { constructor() { this.calledWith_ = arguments; } + // formatName_ = util.noop } class FakeSink { @@ -576,6 +578,36 @@ describe('Logging', () => { stream.emit('reading'); }); + it('should set logName filter if has logName flag', done => { + const logName = 'log-name'; + logging = new LOGGING({projectId: PROJECT_ID}); + logging.loggingService.listLogEntriesStream = (reqOpts, gaxOpts) => { + assert.deepStrictEqual(reqOpts, { + resourceNames: ['projects/' + logging.projectId], + orderBy: 'timestamp desc', + a: 'b', + c: 'd', + filter: `logName="${ + ['projects', PROJECT_ID, 'logs', encodeURIComponent(logName)] + .join('/')}"`, + }); + + assert.deepStrictEqual(gaxOpts, { + autoPaginate: undefined, + a: 'b', + c: 'd', + }); + + setImmediate(done); + + return GAX_STREAM; + }; + + const log = logging.log('log-name'); + const stream = log.getEntriesStream(OPTIONS); + stream.emit('reading'); + }); + it('should destroy request stream if gax fails', done => { const error = new Error('Error.'); logging.loggingService.listLogEntriesStream = () => { diff --git a/test/log.ts b/test/log.ts index e5812de72..fbb2a8066 100644 --- a/test/log.ts +++ b/test/log.ts @@ -277,7 +277,7 @@ describe('Log', () => { describe('getEntriesStream', () => { const fakeStream = {}; const EXPECTED_OPTIONS = { - logName_: LOG_NAME_ENCODED, + log: LOG_NAME_ENCODED, }; it('should call Logging getEntriesStream with defaults', done => {