Skip to content

Commit

Permalink
feat!: logs now truncate to 256,000ish bytes by default (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Oct 18, 2019
1 parent 7a77492 commit bea68ae
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"predocs-test": "npm run docs"
},
"dependencies": {
"@google-cloud/logging": "^5.3.1",
"@google-cloud/logging": "^5.5.2",
"google-auth-library": "^5.2.2",
"lodash.mapvalues": "^4.6.0",
"logform": "^2.1.2",
Expand Down
4 changes: 4 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class LoggingCommon {
this.levels = options.levels || NPM_LEVEL_NAME_TO_CODE;
this.stackdriverLog = new Logging(options).log(this.logName, {
removeCircular: true,
// See: https://cloud.google.com/logging/quotas, a log size of
// 250,000 has been chosen to keep us comfortably within the
// 256,000 limit.
maxEntrySize: options.maxEntrySize || 250000,
});
this.resource = options.resource;
this.serviceContext = options.serviceContext;
Expand Down
3 changes: 3 additions & 0 deletions src/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export interface Options {
labels?: {[key: string]: string};

apiEndpoint?: string;

// An attempt will be made to truncate messages larger than maxEntrySize.
maxEntrySize?: number;
}

export interface MonitoredResource {
Expand Down
5 changes: 4 additions & 1 deletion test/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ describe('logging-common', () => {
it('should set removeCircular to true', () => {
const loggingCommon = new loggingCommonLib.LoggingCommon(OPTIONS);

assert.deepStrictEqual(fakeLogOptions_, {removeCircular: true});
assert.deepStrictEqual(fakeLogOptions_, {
removeCircular: true,
maxEntrySize: 250000,
});
});

it('should localize the provided resource', () => {
Expand Down

0 comments on commit bea68ae

Please sign in to comment.