From 2bbabf1e917a79268ccb5c1e58db451a76fe75e4 Mon Sep 17 00:00:00 2001 From: teawithfruit Date: Thu, 16 Nov 2017 11:32:54 +0100 Subject: [PATCH] added debug functionality and removed console.log --- lib/diskdb.js | 12 +++++------- package.json | 5 +++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/diskdb.js b/lib/diskdb.js index bc13a11..980043b 100644 --- a/lib/diskdb.js +++ b/lib/diskdb.js @@ -11,7 +11,7 @@ var path = require('path'), c = require('chalk'), e = c.red, - s = c.green; + debug = require('debug')('diskdb'); //local modules var util = require('./util'); @@ -23,20 +23,18 @@ var db = { var _db = {}; _db.path = path; this._db = _db; - console.log(s('Successfully connected to : ' + path)); + debug('Successfully connected to : ' + path); if (collections) { this.loadCollections(collections); } } else { - console.log(e('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again')); - return false; + throw(e('The DB Path [' + path + '] does not seem to be valid. Recheck the path and try again')); } return this; }, loadCollections: function(collections) { if (!this._db) { - console.log(e('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');')); - return false; + throw(e('Initialize the DB before you add collections. Use : ', 'db.connect(\'path-to-db\');')); } if (typeof collections === 'object' && collections.length) { for (var i = 0; i < collections.length; i++) { @@ -48,7 +46,7 @@ var db = { this[_c] = new require('./collection')(this, _c); } } else { - console.log(e('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']')); + throw(e('Invalid Collections Array.', 'Expected Format : ', '[\'collection1\',\'collection2\',\'collection3\']')); } return this; } diff --git a/package.json b/package.json index 2676be0..ac8f466 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,9 @@ }, "dependencies": { "chalk": "^0.4.0", - "node-uuid": "^1.4.1", - "merge": "^1.1.3" + "debug": "^3.1.0", + "merge": "^1.1.3", + "node-uuid": "^1.4.1" }, "scripts": { "test": "grunt"