Skip to content

Commit f1e6ff4

Browse files
committed
Fixeds #62
1 parent fbadeda commit f1e6ff4

File tree

4 files changed

+25
-36
lines changed

4 files changed

+25
-36
lines changed

lib/firestack.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class Firestack extends Singleton {
3535

3636
instance.options = options || {};
3737
instance._debug = instance.options.debug || false;
38-
log = instance._log = new Log('firestack', instance._debug);
38+
39+
Log.enable(instance._debug);
40+
log = instance._log = new Log('firestack');
3941

4042
log.info('Creating new firestack instance');
4143

lib/modules/database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class DatabaseRef extends ReferenceBase {
337337
}
338338

339339
get namespace() {
340-
return `firestack:dbRef:${this.dbPath()}`
340+
return `firestack:dbRef`
341341
}
342342
}
343343

lib/utils/log.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,44 @@
11
// document hack
22
import root from './window-or-global'
3+
4+
let bows;
35
(function (base) {
46
window = base || window
5-
if (!window.document) {
6-
window.document = { documentElement: { style: { WebkitAppearance: true } } }
7-
}
87
if(!window.localStorage) window.localStorage = {};
98
})(root);
109

11-
let debug = () => {};
10+
const levels = [
11+
'warn', 'info', 'error', 'debug'
12+
];
1213

1314
export class Log {
14-
constructor(namespace, enable) {
15+
constructor(namespace) {
1516
this._namespace = namespace || 'firestack';
16-
this.l = null;
1717
this.loggers = {};
18-
this.enabled = false;
19-
this.enable(enable);
18+
// Add the logging levels for each level
19+
levels
20+
.forEach(level => this[level] = (...args) => this._log(level)(...args));
2021
}
2122

22-
enable(booleanOrStringDebug) {
23-
window.localStorage.debug =
23+
static enable(booleanOrStringDebug) {
24+
window.localStorage.debug =
2425
typeof booleanOrStringDebug === 'string' ?
25-
booleanOrStringDebug :
26-
(booleanOrStringDebug ? '*' : booleanOrStringDebug);
27-
28-
this.enabled = !!window.localStorage.debug;
29-
}
30-
31-
info(...args) {
32-
this._logger('info')(...args);
33-
}
26+
(booleanOrStringDebug === '*' ? true : booleanOrStringDebug) :
27+
(booleanOrStringDebug instanceof RegExp ? booleanOrStringDebug.toString() : booleanOrStringDebug);
3428

35-
error(...args) {
36-
this._logger('error')(...args);
29+
window.localStorage.debugColors = !!window.localStorage.debug;
3730
}
3831

39-
debug(...args) {
40-
this._logger('debug')(...args);
41-
}
42-
43-
_logger(level) {
32+
_log(level) {
4433
if (!this.loggers[level]) {
45-
this.loggers[level] = this._debug()(`${this._namespace}:${level}`)
34+
(function() {
35+
const bows = require('bows');
36+
bows.config({ padLength: 20 });
37+
this.loggers[level] = bows(this._namespace, `[${level}]`);
38+
}.bind(this))();
4639
}
4740
return this.loggers[level];
4841
}
49-
50-
_debug() {
51-
if (!this.l) {
52-
this.l = debug = require('debug');
53-
}
54-
return this.l;
55-
}
5642
}
5743

5844
export default Log;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"sinon": "^2.0.0-pre.2"
6868
},
6969
"dependencies": {
70+
"bows": "^1.6.0",
7071
"es6-symbol": "^3.1.0"
7172
}
7273
}

0 commit comments

Comments
 (0)