diff --git a/bin/plotly-export-server_electron.js b/bin/plotly-export-server_electron.js index 44e58b47..56f4502c 100644 --- a/bin/plotly-export-server_electron.js +++ b/bin/plotly-export-server_electron.js @@ -4,6 +4,7 @@ const pkg = require('../package.json') const argv = getServerArgs() const SHOW_LOGS = !argv.quiet +const DEBUG = argv.debug if (argv.version) { console.log(pkg.version) @@ -48,7 +49,7 @@ const opts = { launch() app.on('after-connect', (info) => { - if (SHOW_LOGS) { + if (DEBUG) { console.log(`Listening on port ${info.port} after a ${info.startupTime} ms bootup`) console.log(`Open routes: ${info.openRoutes.join(' ')}`) } @@ -56,21 +57,43 @@ app.on('after-connect', (info) => { app.on('after-export', (info) => { if (SHOW_LOGS) { - console.log(`after-export, fig: ${info.fid} in ${info.processingTime} ms`) + console.log(JSON.stringify({ + severity: 'INFO', + httpRequest: { + requestMethod: info.method + }, + labels: { + fid: info.fid, + head: info.head, + processingTime: info.processingTime + } + })) } }) app.on('export-error', (info) => { if (SHOW_LOGS) { - console.log(`export error ${info.code} - ${info.msg}`) + console.log(JSON.stringify({ + severity: 'ERROR', + textPayload: `${info.code} - ${info.msg}`, + labels: { + fid: info.fid, + head: info.head + } + })) } }) process.on('uncaughtException', (err) => { - console.warn(err) + if (SHOW_LOGS) { + console.log(JSON.stringify({ + severity: 'ERROR', + textPayload: err.toString() + })) + } if (argv.keepAlive) { - if (SHOW_LOGS) { + if (DEBUG) { console.log('... relaunching') } launch() @@ -78,6 +101,8 @@ process.on('uncaughtException', (err) => { }) function launch () { - console.log(`Spinning up server with pid: ${process.pid}`) + if (DEBUG) { + console.log(`Spinning up server with pid: ${process.pid}`) + } app = plotlyExporter.serve(opts) } diff --git a/src/app/server/create-server.js b/src/app/server/create-server.js index 5682f2be..7ebdd504 100644 --- a/src/app/server/create-server.js +++ b/src/app/server/create-server.js @@ -31,6 +31,7 @@ function createServer (app, BrowserWindow, ipcMain, opts) { // and is emitted on 'export-error' and 'after-export' const fullInfo = { port: opts.port, + method: req.method, id: id } diff --git a/test/unit/server_test.js b/test/unit/server_test.js index 9e512f2a..3154d302 100644 --- a/test/unit/server_test.js +++ b/test/unit/server_test.js @@ -148,7 +148,8 @@ tap.test('createServer:', t => { const app = args[0] app.on('after-export', (info) => { - t.equal(Object.keys(info).length, 15, '# of keys') + t.equal(Object.keys(info).length, 16, '# of keys') + t.equal(info.method, 'POST', 'method') t.type(info.id, 'string', 'id') t.equal(info.port, args[3].port, 'port') t.equal(info.pending, 0, 'pending') @@ -179,7 +180,7 @@ tap.test('createServer:', t => { t.test('on invalid route', t => { _boot([], (args) => { - wrapApp(t, args, [4, 404, 'invalid route']) + wrapApp(t, args, [5, 404, 'invalid route']) _post('not-gonna-work', body0(), (err, res, body) => { if (err) t.fail() @@ -193,7 +194,7 @@ tap.test('createServer:', t => { const opts = opts0() _boot([false, false, false, opts], (args) => { - wrapApp(t, args, [4, 504, 'window for given route does not exist']) + wrapApp(t, args, [5, 504, 'window for given route does not exist']) _post('', body0(), (err, res, body) => { if (err) t.fail() @@ -208,7 +209,7 @@ tap.test('createServer:', t => { BrowserWindow.getAllWindows = () => ({length: Infinity}) _boot([false, BrowserWindow], (args) => { - wrapApp(t, args, [4, 402, 'too many windows are opened']) + wrapApp(t, args, [5, 402, 'too many windows are opened']) _post('', body0(), (err, res, body) => { if (err) t.fail() @@ -220,7 +221,7 @@ tap.test('createServer:', t => { t.test('on json parse errors', t => { _boot([], (args) => { - wrapApp(t, args, [4, 422, 'json parse error']) + wrapApp(t, args, [5, 422, 'json parse error']) _post('', body0() + '/', (err, res, body) => { if (err) t.fail() @@ -236,7 +237,7 @@ tap.test('createServer:', t => { sinon.stub(_module, 'parse').yields(432) _boot([false, false, false, opts], (args) => { - wrapApp(t, args, [4, 432, '']) + wrapApp(t, args, [5, 432, '']) _post('', body0(), (err, res, body) => { if (err) t.fail() @@ -251,7 +252,7 @@ tap.test('createServer:', t => { const opts = mockWebContents(opts0(), 467, {msg: 'error msg'}) _boot([false, false, false, opts], (args) => { - wrapApp(t, args, [11, 467, 'error msg']) + wrapApp(t, args, [12, 467, 'error msg']) _post('', body0(), (err, res, body) => { if (err) t.fail() @@ -267,7 +268,7 @@ tap.test('createServer:', t => { sinon.stub(_module, 'convert').yields(483) _boot([false, false, false, opts], (args) => { - wrapApp(t, args, [12, 483, '']) + wrapApp(t, args, [13, 483, '']) _post('', body0(), (err, res, body) => { if (err) t.fail()