Skip to content

Commit

Permalink
fix: pass spread args instead of args; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed Sep 6, 2018
1 parent f545013 commit 5c5a72e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,32 @@ export class Logger {

this.logger = consoleLogLevel({
stderr: true,
prefix: opts && opts.tag ? opts.tag : '@google-cloud/trace-agent',
prefix: opts && opts.tag ? opts.tag : 'unknown',
level: levelName as ConsoleLogLevel
});
}

error(...args: Array<{}>): void {
if (this.logger) {
this.logger.error(args);
this.logger.error(...args);
}
}

warn(...args: Array<{}>): void {
if (this.logger) {
this.logger.warn(args);
this.logger.warn(...args);
}
}

debug(...args: Array<{}>): void {
if (this.logger) {
this.logger.debug(args);
this.logger.debug(...args);
}
}

info(...args: Array<{}>): void {
if (this.logger) {
this.logger.info(args);
this.logger.info(...args);
}
}
}
2 changes: 1 addition & 1 deletion test/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class TestLogger extends Logger {
new OriginalLogger({level: LEVELS[PASS_THROUGH_LOG_LEVEL]});

constructor(options?: Partial<LoggerConfig>) {
super(options);
super(Object.assign({tag: '@google-cloud/trace-agent'}, options));
}

private makeLoggerFn(logLevel: keyof Logger): LoggerFunction<this> {
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import { StackdriverTracer } from '../../src/trace-api';
import { traceWriter } from '../../src/trace-writer';
import * as TracingPolicy from '../../src/tracing-policy';
import { SpanType } from '../../src/constants';
import { TestLogger } from '../logger';

var semver = require('semver');

var logger = require('@google-cloud/common').logger;
var trace = require('../../..');
if (semver.satisfies(process.version, '>=8')) {
// Monkeypatch Mocha's it() to create a fresh context with each test case.
Expand Down Expand Up @@ -75,7 +75,7 @@ shimmer.wrap(trace, 'start', function(original) {
ignoreContextHeader: false,
rootSpanNameOverride: (name: string) => name,
samplingRate: 0
}, logger());
}, new TestLogger());
testTraceAgent.policy = new TracingPolicy.TraceAllPolicy();
return result;
};
Expand Down
4 changes: 1 addition & 3 deletions test/test-env-log-level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* limitations under the License.
*/

import * as common from '@google-cloud/common';
import * as assert from 'assert';
import * as shimmer from 'shimmer';

import * as logger from '../src/logger';
import {FORCE_NEW} from '../src/util';

import {TestLogger} from './logger';
import * as traceTestModule from './trace';
Expand Down Expand Up @@ -69,6 +67,6 @@ describe('should respect environment variables', () => {
assert.strictEqual(logLevel, logger.LEVELS[0]);
process.env.GCLOUD_TRACE_LOGLEVEL = '300';
traceTestModule.start();
assert.strictEqual(logLevel, logger.LEVELS[5]);
assert.strictEqual(logLevel, logger.LEVELS[4]);
});
});
1 change: 0 additions & 1 deletion test/test-modules-loaded-before-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import * as common from '@google-cloud/common';
import * as assert from 'assert';
import * as shimmer from 'shimmer';

Expand Down
1 change: 0 additions & 1 deletion test/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* Most tests should include this file instead of the main module root.
*/

import * as common from '@google-cloud/common';
import * as assert from 'assert';
import * as shimmer from 'shimmer';

Expand Down

0 comments on commit 5c5a72e

Please sign in to comment.