diff --git a/js/models/PublicKeyRing.js b/js/models/PublicKeyRing.js index 8b1efb994..9bfe0caab 100644 --- a/js/models/PublicKeyRing.js +++ b/js/models/PublicKeyRing.js @@ -110,7 +110,7 @@ PublicKeyRing.fromObj = function(opts) { } if (opts.cache && opts.cache.addressToPath) { - log.info('PublicKeyRing: Using address cache'); + log.debug('PublicKeyRing: Using address cache'); pkr.cache.addressToPath = opts.cache.addressToPath; pkr.rebuildCache(); } diff --git a/js/plugins/LocalStorage.js b/js/plugins/LocalStorage.js index ccdfaa1a8..0692a13ae 100644 --- a/js/plugins/LocalStorage.js +++ b/js/plugins/LocalStorage.js @@ -1,8 +1,12 @@ 'use strict'; var _ = require('lodash'); +var preconditions = require('preconditions').singleton(); function LocalStorage() { this.type = 'DB'; + + preconditions.checkState(typeof localStorage !== 'undefined', + 'localstorage not available, cannot run plugin'); }; LocalStorage.prototype.init = function() { diff --git a/js/util/log.js b/js/util/log.js index 10d14077c..27a2f02aa 100644 --- a/js/util/log.js +++ b/js/util/log.js @@ -1,9 +1,11 @@ var config = config || require('../../config'); var _ = require('lodash'); +var ls; -var LS = require('../plugins/LocalStorage'); -var ls = new LS(); - +try { + var LS = require('../plugins/LocalStorage'); + ls = new LS(); +} catch(e) {}; /** * @desc @@ -122,9 +124,9 @@ Logger.prototype.setLevel = function(level) { var logger = new Logger('copay'); var error = new Error(); -var logLevel = config.logLevel; +var logLevel = config.logLevel || 'info'; -if (ls.getItem) { +if (ls && ls.getItem) { ls.getItem("config", function(err, value) { if (err) return; var localConfig = JSON.parse(value); diff --git a/test/util.log.js b/test/util.log.js new file mode 100644 index 000000000..c6749c528 --- /dev/null +++ b/test/util.log.js @@ -0,0 +1,39 @@ +'use strict'; + +var _ = require('lodash'); +var chai = chai || require('chai'); +var sinon = sinon || require('sinon'); +var should = chai.should(); +var log = require('../js/util/log'); + +describe.only('log utils', function() { + afterEach(function() { + log.setLevel('info'); + }); + + it('should log debug', function() { + sinon.stub(console,'log'); + log.setLevel('debug'); + log.debug('hola'); + + var arg = console.log.getCall(0).args[0]; + arg.should.contain('util.log.js'); + arg.should.contain('hola'); + console.log.restore(); + }); + + it('should not log debug', function() { + sinon.stub(console,'log'); + log.setLevel('info'); + log.debug('hola'); + console.log.called.should.equal(false); + console.log.restore(); + }); + + it('should log debug', function() { + log.getLevels().debug.should.equal(0); + log.getLevels().fatal.should.equal(5); + }); + + +});