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

Notifier logging #4464

Merged
merged 6 commits into from
Jan 6, 2020
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
44 changes: 35 additions & 9 deletions src/lib/loggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

var dfltConfig = require('../plot_api/plot_config').dfltConfig;

var notifier = require('./notifier');

var loggers = module.exports = {};

/**
Expand All @@ -21,39 +23,63 @@ var loggers = module.exports = {};
*/

loggers.log = function() {
var i;

if(dfltConfig.logging > 1) {
var messages = ['LOG:'];

for(var i = 0; i < arguments.length; i++) {
for(i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}

apply(console.trace || console.log, messages);
}

if(dfltConfig.notifyOnLogging > 1) {
var lines = [];
for(i = 0; i < arguments.length; i++) {
lines.push(arguments[i]);
}
notifier(lines.join('<br>'), 'long');
}
};

loggers.warn = function() {
var i;

if(dfltConfig.logging > 0) {
var messages = ['WARN:'];

for(var i = 0; i < arguments.length; i++) {
for(i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}

apply(console.trace || console.log, messages);
}

if(dfltConfig.notifyOnLogging > 0) {
var lines = [];
for(i = 0; i < arguments.length; i++) {
lines.push(arguments[i]);
}
notifier(lines.join('<br>'), 'stick');
}
};

loggers.error = function() {
var i;

if(dfltConfig.logging > 0) {
var messages = ['ERROR:'];

for(var i = 0; i < arguments.length; i++) {
for(i = 0; i < arguments.length; i++) {
messages.push(arguments[i]);
}

apply(console.error, messages);
}

if(dfltConfig.notifyOnLogging > 0) {
var lines = [];
for(i = 0; i < arguments.length; i++) {
lines.push(arguments[i]);
}
notifier(lines.join('<br>'), 'stick');
}
};

/*
Expand Down
18 changes: 12 additions & 6 deletions src/lib/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ module.exports = function(text, displayLength) {
p.append('span').text(lines[i]);
}

note.transition()
.duration(700)
.style('opacity', 1)
.transition()
.delay(ts)
.call(killNote);
if(displayLength === 'stick') {
note.transition()
.duration(350)
.style('opacity', 1);
} else {
note.transition()
.duration(700)
.style('opacity', 1)
.transition()
.delay(ts)
.call(killNote);
}
});
};
19 changes: 18 additions & 1 deletion src/plot_api/plot_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ var configAttributes = {
},

logging: {
valType: 'boolean',
valType: 'integer',
min: 0,
max: 2,
dflt: 1,
description: [
'Turn all console logging on or off (errors will be thrown)',
Expand All @@ -388,6 +390,21 @@ var configAttributes = {
].join(' ')
},

notifyOnLogging: {
valType: 'integer',
min: 0,
max: 2,
dflt: 0,
description: [
'Set on-graph logging (notifier) level',
'This should ONLY be set via Plotly.setPlotConfig',
'Available levels:',
'0: no on-graph logs',
'1: warnings and errors, but not informational messages',
'2: verbose logs'
].join(' ')
},

queueLength: {
valType: 'integer',
min: 0,
Expand Down
1 change: 1 addition & 0 deletions src/plots/mapbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function findAccessToken(gd, mapboxIds) {
var msg = hasOneSetMapboxStyle ?
constants.noAccessTokenErrorMsg :
constants.missingStyleErrorMsg;
Lib.error(msg);
throw new Error(msg);
}

Expand Down
1 change: 1 addition & 0 deletions test/image/compare_pixels_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if(allMock || argv.filter) {

var FLAKY_LIST = [
'treemap_textposition',
'treemap_with-without_values_template',
'trace_metatext',
'gl3d_directions-streamtube1'
];
Expand Down
51 changes: 49 additions & 2 deletions test/jasmine/tests/lib_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1671,8 +1671,9 @@ describe('Test lib.js:', function() {
});

describe('loggers', function() {
var stashConsole,
stashLogLevel;
var stashConsole;
var stashLogLevel;
var stashOnGraphLogLevel;

function consoleFn(name, hasApply, messages) {
var out = function() {
Expand Down Expand Up @@ -1703,11 +1704,13 @@ describe('Test lib.js:', function() {
beforeEach(function() {
stashConsole = window.console;
stashLogLevel = config.logging;
stashOnGraphLogLevel = config.notifyOnLogging;
});

afterEach(function() {
window.console = stashConsole;
config.logging = stashLogLevel;
config.notifyOnLogging = stashOnGraphLogLevel;
});

it('emits one console message if apply is available', function() {
Expand Down Expand Up @@ -1807,6 +1810,50 @@ describe('Test lib.js:', function() {
['log', [{a: 1, b: 2}]]
]);
});

describe('should log message in notifier div in accordance notifyOnLogging config option', function() {
var query = '.notifier-note';

beforeEach(function(done) {
d3.selectAll(query).each(function() {
d3.select(this).select('button').node().click();
});
setTimeout(done, 1000);
});

function _run(exp) {
config.logging = 0;

Lib.log('log');
Lib.warn('warn');
Lib.error('error!');

var notes = d3.selectAll(query);

expect(notes.size()).toBe(exp.length, '# of notifier notes');

var actual = [];
notes.each(function() {
actual.push(d3.select(this).select('p').text());
});
expect(actual).toEqual(exp);
}

it('with level 2', function() {
config.notifyOnLogging = 2;
_run(['log', 'warn', 'error!']);
});

it('with level 1', function() {
config.notifyOnLogging = 1;
_run(['warn', 'error!']);
});

it('with level 0', function() {
config.notifyOnLogging = 0;
_run([]);
});
});
});

describe('keyedContainer', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ describe('mapbox credentials', function() {
}]);
}).toThrow(new Error(constants.missingStyleErrorMsg));

expect(Lib.error).toHaveBeenCalledTimes(0);
expect(Lib.error).toHaveBeenCalledWith(constants.missingStyleErrorMsg);
}, LONG_TIMEOUT_INTERVAL);

it('@gl should throw error when setting a Mapbox style w/o a registered token', function() {
Expand Down