From 70bfa806da6af6f598671482e5ec5005de7a2648 Mon Sep 17 00:00:00 2001 From: Mark Wilson Date: Thu, 15 Oct 2015 18:35:28 -0700 Subject: [PATCH] Make logger verbosity more explicitly configurable --- index.js | 1 + logger.js | 19 ++++++++++++++----- run.js | 6 +++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 6c3b69d..375ffdb 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ module.exports = { carelink: require('./carelink'), + logger: require('./logger'), nightscout: require('./nightscout'), transform: require('./transform') }; diff --git a/logger.js b/logger.js index 80ee924..c859be3 100644 --- a/logger.js +++ b/logger.js @@ -1,8 +1,17 @@ /* jshint node: true */ "use strict"; -module.exports.log = function(str) { - if (process.env['CARELINK_VERBOSE']) { - console.log(new Date() + ' ' + str); - } -}; +module.exports = (function() { + var verbose_ = false; + + return { + setVerbose: function(v) { + verbose_ = v; + }, + log: function(str) { + if(verbose_) { + console.log(new Date() + ' ' + str); + } + } + }; +})(); diff --git a/run.js b/run.js index 90d39d7..eaac5cc 100644 --- a/run.js +++ b/run.js @@ -2,6 +2,7 @@ "use strict"; var carelink = require('./carelink'), + logger = require('./logger'), nightscout = require('./nightscout'), transform = require('./transform'); @@ -22,7 +23,8 @@ var config = { nsSecret: readEnv('API_SECRET'), interval: parseInt(readEnv('CARELINK_REQUEST_INTERVAL', 60 * 1000), 10), sgvLimit: parseInt(readEnv('CARELINK_SGV_LIMIT', 24), 10), - maxRetryDuration: parseInt(readEnv('CARELINK_MAX_RETRY_DURATION', carelink.defaultMaxRetryDuration), 10) + maxRetryDuration: parseInt(readEnv('CARELINK_MAX_RETRY_DURATION', carelink.defaultMaxRetryDuration), 10), + verbose: !!readEnv('CARELINK_VERBOSE') }; if (!config.username) { @@ -38,6 +40,8 @@ var client = carelink.Client({ }); var endpoint = (config.nsBaseUrl ? config.nsBaseUrl : 'https://' + config.nsHost) + '/api/v1/entries.json'; +logger.setVerbose(config.verbose); + (function requestLoop() { client.fetch(function(err, data) { if (err) {