Skip to content

Commit

Permalink
Make logger verbosity more explicitly configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mddub committed Oct 16, 2015
1 parent 1ae5558 commit 70bfa80
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
carelink: require('./carelink'),
logger: require('./logger'),
nightscout: require('./nightscout'),
transform: require('./transform')
};
19 changes: 14 additions & 5 deletions logger.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
};
})();
6 changes: 5 additions & 1 deletion run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"use strict";

var carelink = require('./carelink'),
logger = require('./logger'),
nightscout = require('./nightscout'),
transform = require('./transform');

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 70bfa80

Please sign in to comment.