Skip to content

Commit

Permalink
Add LOG_LEVEL parameter, suppress logs for unit tests (cloudspannerec…
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybell authored Feb 27, 2024
1 parent 26ad50f commit cd3d881
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 213 deletions.
17 changes: 16 additions & 1 deletion src/autoscaler-common/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
const bunyan = require('bunyan');
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');

/**
* Return a bunyan level based on environment variables (or lack thereof).
*
* @return {bunyan.LogLevel}
*/
function getLogLevel() {
if (process.env.LOG_LEVEL) {
return bunyan.levelFromName[process.env.LOG_LEVEL.toLowerCase()];
} else if (process.env.NODE_ENV?.toLowerCase() === 'test') {
return bunyan.FATAL;
} else {
return bunyan.DEBUG;
}
}

// Create logging client.
const loggingBunyan = new LoggingBunyan({
redirectToStdout: true,
Expand All @@ -29,7 +44,7 @@ const loggingBunyan = new LoggingBunyan({
const logger = bunyan.createLogger({
name: 'cloud-spanner-autoscaler',
streams: [
loggingBunyan.stream('trace'),
loggingBunyan.stream(getLogLevel()),
],
});

Expand Down
104 changes: 48 additions & 56 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd3d881

Please sign in to comment.