Skip to content

Commit

Permalink
fix: only apply logName to filter when not already present (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Dec 2, 2020
1 parent 3d63d5f commit f1fbbc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ class Log implements LogSeverityFunctions {
const options = extend({}, opts as GetEntriesRequest);
const projectId = await this.logging.auth.getProjectId();
this.formattedName_ = Log.formatName_(projectId, this.name);
if (options.filter) {
if (options.filter && !options.filter.includes('logName=')) {
options.filter = `(${options.filter}) AND logName="${this.formattedName_}"`;
} else {
} else if (!options.filter) {
options.filter = `logName="${this.formattedName_}"`;
}
return this.logging.getEntries(options);
Expand Down
8 changes: 8 additions & 0 deletions test/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ describe('Log', () => {
await log.getEntries(options);
assert(log.logging.getEntries.calledWithExactly(expectedOptions));
});

it('should not add logName filter if already present', async () => {
const filter = `logName="${LOG_NAME_FORMATTED}" AND custom filter`;
const options = {filter};

await log.getEntries(options);
assert(log.logging.getEntries.calledWithExactly({filter}));
});
});

describe('getEntriesStream', () => {
Expand Down

0 comments on commit f1fbbc4

Please sign in to comment.