Skip to content

Commit

Permalink
Test log level correction (#424)
Browse files Browse the repository at this point in the history
PR-URL: #424
  • Loading branch information
matthewloring authored Feb 28, 2017
1 parent e74b60a commit c68c22f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 5 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ function start(projectConfig) {
return traceApi;
}

var logLevel = config.logLevel;
if (logLevel < 0) {
logLevel = 0;
} else if (logLevel >= common.logger.LEVELS.length) {
logLevel = common.logger.LEVELS.length - 1;
if (config.logLevel < 0) {
config.logLevel = 0;
} else if (config.logLevel >= common.logger.LEVELS.length) {
config.logLevel = common.logger.LEVELS.length - 1;
}
var logger = common.logger({
level: common.logger.LEVELS[logLevel],
level: common.logger.LEVELS[config.logLevel],
tag: '@google/cloud-trace'
});

Expand Down
9 changes: 9 additions & 0 deletions test/test-env-log-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ describe('should respect environment variables', function() {
var agent = trace.start({logLevel: 2, forceNewAgent_: true});
assert.equal(common.getConfig(agent).logLevel, 4);
});

it('should fix out of bounds log level', function() {
process.env.GCLOUD_TRACE_LOGLEVEL = -5;
var agent = trace.start({forceNewAgent_: true});
assert.equal(common.getConfig(agent).logLevel, 0);
process.env.GCLOUD_TRACE_LOGLEVEL = 300;
agent = trace.start({forceNewAgent_: true});
assert.equal(common.getConfig(agent).logLevel, 5);
});
});

0 comments on commit c68c22f

Please sign in to comment.