Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't reset the stored log level to default when it's TRACE #35

Merged
merged 3 commits into from
Dec 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/loglevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (self.levels[storedLevel] === undefined) {
storedLevel = "WARN";
}

self.setLevel(self.levels[storedLevel] || self.levels.WARN);
self.setLevel(self.levels[storedLevel]);
}

/*
Expand Down
41 changes: 41 additions & 0 deletions test/local-storage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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";
Expand Down