From 8fc1123f7ab439c8db4c64fa8c1464098b36b04f Mon Sep 17 00:00:00 2001 From: Matthew-Edwards Date: Thu, 12 Dec 2013 17:11:23 +1300 Subject: [PATCH 1/3] Don't reset the stored log level to default when it's TRACE --- lib/loglevel.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/loglevel.js b/lib/loglevel.js index f363c4e..3bfa07d 100644 --- a/lib/loglevel.js +++ b/lib/loglevel.js @@ -127,12 +127,16 @@ storedLevel = window.localStorage['loglevel']; } - if (!storedLevel && cookiesAvailable()) { + if (storedLevel === undefined && cookiesAvailable()) { var cookieMatch = cookieRegex.exec(window.document.cookie) || []; storedLevel = cookieMatch[1]; } + + if (storedLevel === undefined) { + storedLevel = "WARN"; + } - self.setLevel(self.levels[storedLevel] || self.levels.WARN); + self.setLevel(self.levels[storedLevel]); } /* From 12ae7f2e796d5c618800433382e7f14dcc81a2c9 Mon Sep 17 00:00:00 2001 From: Matthew-Edwards Date: Fri, 13 Dec 2013 12:18:28 +1300 Subject: [PATCH 2/3] Fix loading an invalid stored level --- lib/loglevel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loglevel.js b/lib/loglevel.js index 3bfa07d..7b97d31 100644 --- a/lib/loglevel.js +++ b/lib/loglevel.js @@ -132,7 +132,7 @@ storedLevel = cookieMatch[1]; } - if (storedLevel === undefined) { + if (self.levels[storedLevel] === undefined) { storedLevel = "WARN"; } From 9c8e1ada494137bf58bee5e4b66f9ea91c3d05ab Mon Sep 17 00:00:00 2001 From: Matthew-Edwards Date: Fri, 13 Dec 2013 12:18:55 +1300 Subject: [PATCH 3/3] Add more tests for loading stored levels --- test/local-storage-test.js | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/local-storage-test.js b/test/local-storage-test.js index 6a75bac..274bf0c 100644 --- a/test/local-storage-test.js +++ b/test/local-storage-test.js @@ -44,7 +44,27 @@ define(['test/test-helpers'], function(testHelpers) { expect("debug").toBeTheStoredLevel(); }); }); + + describe("If trace level is saved", function () { + beforeEach(function () { + testHelpers.setStoredLevel("trace"); + }); + + it("trace is the default log level", function (log) { + expect(log).toBeAtLevel("trace"); + }); + }); + + describe("If debug level is saved", function () { + beforeEach(function () { + testHelpers.setStoredLevel("debug"); + }); + it("debug is the default log level", function (log) { + expect(log).toBeAtLevel("debug"); + }); + }); + describe("If info level is saved", function() { beforeEach(function() { testHelpers.setStoredLevel("info"); @@ -67,6 +87,27 @@ define(['test/test-helpers'], function(testHelpers) { }); }); + describe("If warn level is saved", function () { + beforeEach(function () { + testHelpers.setStoredLevel("warn"); + }); + + it("warn is the default log level", function (log) { + expect(log).toBeAtLevel("warn"); + }); + }); + + describe("If error level is saved", function () { + beforeEach(function () { + testHelpers.setStoredLevel("error"); + }); + + it("error is the default log level", function (log) { + expect(log).toBeAtLevel("error"); + }); + }); + + describe("If the level is saved with other data", function() { beforeEach(function() { window.localStorage['qwe'] = "asd";