From 91e99c84caf3b4887d014a03ec1ca57e06716723 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 29 Mar 2021 20:06:33 -0400 Subject: [PATCH] import: Reduce log spam from unsupported elements --- src/node/utils/ImportEtherpad.js | 15 +++++++++++---- src/static/js/contentcollector.js | 12 ++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index 459d5a38b..b90718a57 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -18,8 +18,11 @@ const db = require('../db/DB'); const hooks = require('../../static/js/pluginfw/hooks'); +const log4js = require('log4js'); const supportedElems = require('../../static/js/contentcollector').supportedElems; +const logger = log4js.getLogger('ImportEtherpad'); + exports.setPadRaw = (padId, r) => { const records = JSON.parse(r); @@ -28,6 +31,8 @@ exports.setPadRaw = (padId, r) => { supportedElems.add(element); }); + const unsupportedElements = new Set(); + Object.keys(records).forEach(async (key) => { let value = records[key]; @@ -64,10 +69,7 @@ exports.setPadRaw = (padId, r) => { if (value.pool) { for (const attrib of Object.keys(value.pool.numToAttrib)) { const attribName = value.pool.numToAttrib[attrib][0]; - if (!supportedElems.has(attribName)) { - console.warn('Plugin missing: ' + - `You might want to install a plugin to support this node name: ${attribName}`); - } + if (!supportedElems.has(attribName)) unsupportedElements.add(attribName); } } const oldPadId = key.split(':'); @@ -92,4 +94,9 @@ exports.setPadRaw = (padId, r) => { // Write the value to the server await db.set(newKey, value); }); + + if (unsupportedElements.size) { + logger.warn('Ignoring unsupported elements (you might want to install a plugin): ' + + `${[...unsupportedElements].join(', ')}`); + } }; diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 1b7ef51d3..c02e73887 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -318,6 +318,7 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) cc.incrementAttrib(state, na); }; cc.collectContent = function (node, state) { + let unsupportedElements = null; if (!state) { state = { flags: { /* name -> nesting counter*/ @@ -333,16 +334,15 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) 'list': 'bullet1', */ }, + unsupportedElements: new Set(), }; + unsupportedElements = state.unsupportedElements; } const localAttribs = state.localAttribs; state.localAttribs = null; const isBlock = isBlockElement(node); if (!isBlock && node.name && (node.name !== 'body')) { - if (!supportedElems.has(node.name)) { - console.warn('Plugin missing: ' + - `You might want to install a plugin to support this node name: ${node.name}`); - } + if (!supportedElems.has(node.name)) state.unsupportedElements.add(node.name); } const isEmpty = _isEmpty(node, state); if (isBlock) _ensureColumnZero(state); @@ -621,6 +621,10 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) } } state.localAttribs = localAttribs; + if (unsupportedElements && unsupportedElements.size) { + console.warn('Ignoring unsupported elements (you might want to install a plugin): ' + + `${[...unsupportedElements].join(', ')}`); + } }; // can pass a falsy value for end of doc cc.notifyNextNode = (node) => {