Skip to content

Commit 05abca0

Browse files
committed
Lib: Logging PR Fixups
1 parent 43851c0 commit 05abca0

File tree

5 files changed

+72
-52
lines changed

5 files changed

+72
-52
lines changed

devtools/test_dashboard/devtools.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ var Tabs = {
1313

1414
// Set plot config options
1515
setPlotConfig: function() {
16-
17-
// use local topojson files
18-
Plotly.setPlotConfig({ topojsonURL: '../../dist/topojson/' });
16+
Plotly.setPlotConfig({
17+
// use local topojson files
18+
topojsonURL: '../../dist/topojson/',
19+
logging: 2
20+
});
1921
},
2022

2123
// Return the specified plot container (or default one)
@@ -129,7 +131,7 @@ var Tabs = {
129131
var interval = setInterval(function() {
130132
if(window.Plotly) {
131133
clearInterval(interval);
132-
Tabs.setPlotConfig({ logging: 2 });
134+
Tabs.setPlotConfig();
133135
Tabs.onReload();
134136
}
135137
}, 100);

src/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
},
1111
"rules": {
1212
"strict": [2, "global"],
13-
"no-console": [1]
13+
"no-console": [2]
1414
}
1515
}

src/lib/index.js

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
var d3 = require('d3');
1313

1414
var lib = module.exports = {};
15-
var config = require('../plot_api/plot_config');
1615

1716
lib.nestedProperty = require('./nested_property');
1817
lib.isPlainObject = require('./is_plain_object');
@@ -59,6 +58,11 @@ lib.extendFlat = extendModule.extendFlat;
5958
lib.extendDeep = extendModule.extendDeep;
6059
lib.extendDeepAll = extendModule.extendDeepAll;
6160

61+
var loggersModule = require('./loggers');
62+
lib.log = loggersModule.log;
63+
lib.warn = loggersModule.warn;
64+
lib.error = loggersModule.error;
65+
6266
lib.notifier = require('./notifier');
6367

6468
/**
@@ -93,52 +97,6 @@ lib.pauseEvent = function(e) {
9397
return false;
9498
};
9599

96-
/**
97-
* ------------------------------------------
98-
* debugging tools
99-
* ------------------------------------------
100-
*/
101-
102-
/* eslint-disable no-console */
103-
lib.log = function() {
104-
if(config.logging > 1) {
105-
var messages = ['LOG:'];
106-
107-
for(var i = 0; i < arguments.length; i++) {
108-
messages.push(arguments[i]);
109-
}
110-
111-
if(console.trace) {
112-
console.trace.apply(console, messages);
113-
} else {
114-
console.log.apply(console, messages);
115-
}
116-
}
117-
};
118-
119-
lib.warn = function() {
120-
if(config.logging > 0) {
121-
var messages = ['WARN:'];
122-
123-
for(var i = 0; i < arguments.length; i++) {
124-
messages.push(arguments[i]);
125-
}
126-
127-
if(console.trace) {
128-
console.trace.apply(console, messages);
129-
} else {
130-
console.log.apply(console, messages);
131-
}
132-
}
133-
};
134-
135-
lib.error = function() {
136-
if(config.logging > 0) {
137-
console.error.apply(console, arguments);
138-
}
139-
};
140-
/* eslint-enable no-console */
141-
142100
// constrain - restrict a number v to be between v0 and v1
143101
lib.constrain = function(v, v0, v1) {
144102
if(v0 > v1) return Math.max(v1, Math.min(v0, v));

src/lib/loggers.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Copyright 2012-2016, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
var config = require('../plot_api/plot_config');
12+
13+
var loggers = module.exports = {};
14+
15+
/**
16+
* ------------------------------------------
17+
* debugging tools
18+
* ------------------------------------------
19+
*/
20+
21+
/* eslint-disable no-console */
22+
loggers.log = function() {
23+
if(config.logging > 1) {
24+
var messages = ['LOG:'];
25+
26+
for(var i = 0; i < arguments.length; i++) {
27+
messages.push(arguments[i]);
28+
}
29+
30+
if(console.trace) {
31+
console.trace.apply(console, messages);
32+
} else {
33+
console.log.apply(console, messages);
34+
}
35+
}
36+
};
37+
38+
loggers.warn = function() {
39+
if(config.logging > 0) {
40+
var messages = ['WARN:'];
41+
42+
for(var i = 0; i < arguments.length; i++) {
43+
messages.push(arguments[i]);
44+
}
45+
46+
if(console.trace) {
47+
console.trace.apply(console, messages);
48+
} else {
49+
console.log.apply(console, messages);
50+
}
51+
}
52+
};
53+
54+
loggers.error = function() {
55+
if(config.logging > 0) {
56+
console.error.apply(console, arguments);
57+
}
58+
};
59+
/* eslint-enable no-console */

src/plot_api/plot_config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ module.exports = {
8787
topojsonURL: 'https://cdn.plot.ly/',
8888

8989
// Turn all console logging on or off (errors will be thrown)
90+
// This should ONLY be set via Plotly.setPlotConfig
9091
logging: false
9192
};
9293

0 commit comments

Comments
 (0)