Skip to content

Commit 45d2586

Browse files
committed
Add support to localStorage.debug
1 parent b515049 commit 45d2586

File tree

8 files changed

+316
-42
lines changed

8 files changed

+316
-42
lines changed

dist/logdown.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,42 @@
204204
}
205205

206206
function updateEnabledDisabled () {
207-
// Parsing `NODE_DEBUG` and `DEBUG` env var.
208-
var envVar = null
209-
if (typeof process !== 'undefined' &&
210-
process.env !== undefined &&
211-
filterRegExps.length === 0) {
212-
// `NODE_DEBUG` has precedence over `DEBUG`
213-
if (process.env.NODE_DEBUG !== undefined &&
214-
process.env.NODE_DEBUG !== '') {
215-
envVar = 'NODE_DEBUG'
216-
} else if (process.env.DEBUG !== undefined &&
217-
process.env.DEBUG !== '') {
218-
envVar = 'DEBUG'
219-
}
207+
if (isNode()) {
208+
// Parsing `NODE_DEBUG` and `DEBUG` env var.
209+
var envVar = null
210+
if (
211+
typeof process !== 'undefined' &&
212+
process.env !== undefined
213+
) {
214+
// `NODE_DEBUG` has precedence over `DEBUG`
215+
if (
216+
process.env.NODE_DEBUG !== undefined &&
217+
process.env.NODE_DEBUG !== ''
218+
) {
219+
envVar = 'NODE_DEBUG'
220+
} else if (
221+
process.env.DEBUG !== undefined &&
222+
process.env.DEBUG !== ''
223+
) {
224+
envVar = 'DEBUG'
225+
}
220226

221-
if (envVar) {
227+
if (envVar) {
228+
Logdown.disable('*')
229+
process.env[envVar]
230+
.split(',')
231+
.forEach(function (regExp) {
232+
Logdown.enable(regExp)
233+
})
234+
}
235+
}
236+
} else if (isBrowser()) {
237+
if (
238+
window.localStorage &&
239+
typeof window.localStorage.getItem('debug') === 'string'
240+
) {
222241
Logdown.disable('*')
223-
process.env[envVar]
242+
window.localStorage.debug
224243
.split(',')
225244
.forEach(function (regExp) {
226245
Logdown.enable(regExp)

dist/logdown.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/logdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)