mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
plugins: Improve logging of plugin events
This will make it easier to troubleshoot plugin and npm issues.
This commit is contained in:
parent
4253a2ea8f
commit
dcf7891316
3 changed files with 24 additions and 14 deletions
|
@ -21,13 +21,8 @@ const stderrLogger = (line) => npmLogger.error(line);
|
||||||
*/
|
*/
|
||||||
module.exports = exports = (args, opts = {}) => {
|
module.exports = exports = (args, opts = {}) => {
|
||||||
const cmd = ['npm', ...args];
|
const cmd = ['npm', ...args];
|
||||||
logger.info(`Executing command: ${cmd.join(' ')}`);
|
|
||||||
const p = runCmd(cmd, {stdoutLogger, stderrLogger, ...opts});
|
|
||||||
p.then(
|
|
||||||
() => logger.info(`Successfully ran command: ${cmd.join(' ')}`),
|
|
||||||
() => logger.error(`npm command failed: ${cmd.join(' ')}`));
|
|
||||||
// MUST return the original Promise returned from runCmd so that the caller can access stdout.
|
// MUST return the original Promise returned from runCmd so that the caller can access stdout.
|
||||||
return p;
|
return runCmd(cmd, {stdoutLogger, stderrLogger, ...opts});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Log the version of npm at startup.
|
// Log the version of npm at startup.
|
||||||
|
|
|
@ -7,6 +7,8 @@ const npm = require('npm');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
|
const logger = log4js.getLogger('plugins');
|
||||||
|
|
||||||
let npmIsLoaded = false;
|
let npmIsLoaded = false;
|
||||||
const loadNpm = async () => {
|
const loadNpm = async () => {
|
||||||
if (npmIsLoaded) return;
|
if (npmIsLoaded) return;
|
||||||
|
@ -33,13 +35,16 @@ const wrapTaskCb = (cb) => {
|
||||||
|
|
||||||
exports.uninstall = async (pluginName, cb = null) => {
|
exports.uninstall = async (pluginName, cb = null) => {
|
||||||
cb = wrapTaskCb(cb);
|
cb = wrapTaskCb(cb);
|
||||||
|
logger.info(`Uninstalling plugin ${pluginName}...`);
|
||||||
try {
|
try {
|
||||||
await loadNpm();
|
await loadNpm();
|
||||||
await util.promisify(npm.commands.uninstall)([pluginName]);
|
await util.promisify(npm.commands.uninstall)([pluginName]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
logger.error(`Failed to uninstall plugin ${pluginName}`);
|
||||||
cb(err || new Error(err));
|
cb(err || new Error(err));
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
logger.info(`Successfully uninstalled plugin ${pluginName}`);
|
||||||
await hooks.aCallAll('pluginUninstall', {pluginName});
|
await hooks.aCallAll('pluginUninstall', {pluginName});
|
||||||
await plugins.update();
|
await plugins.update();
|
||||||
cb(null);
|
cb(null);
|
||||||
|
@ -47,13 +52,16 @@ exports.uninstall = async (pluginName, cb = null) => {
|
||||||
|
|
||||||
exports.install = async (pluginName, cb = null) => {
|
exports.install = async (pluginName, cb = null) => {
|
||||||
cb = wrapTaskCb(cb);
|
cb = wrapTaskCb(cb);
|
||||||
|
logger.info(`Installing plugin ${pluginName}...`);
|
||||||
try {
|
try {
|
||||||
await loadNpm();
|
await loadNpm();
|
||||||
await util.promisify(npm.commands.install)([`${pluginName}@latest`]);
|
await util.promisify(npm.commands.install)([`${pluginName}@latest`]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
logger.error(`Failed to install plugin ${pluginName}`);
|
||||||
cb(err || new Error(err));
|
cb(err || new Error(err));
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
logger.info(`Successfully installed plugin ${pluginName}`);
|
||||||
await hooks.aCallAll('pluginInstall', {pluginName});
|
await hooks.aCallAll('pluginInstall', {pluginName});
|
||||||
await plugins.update();
|
await plugins.update();
|
||||||
cb(null);
|
cb(null);
|
||||||
|
@ -77,7 +85,7 @@ exports.getAvailablePlugins = (maxCacheAge) => {
|
||||||
try {
|
try {
|
||||||
plugins = JSON.parse(plugins);
|
plugins = JSON.parse(plugins);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('error parsing plugins.json:', err);
|
logger.error(`error parsing plugins.json: ${err.stack || err}`);
|
||||||
plugins = [];
|
plugins = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +115,7 @@ exports.search = (searchTerm, maxCacheAge) => exports.getAvailablePlugins(maxCac
|
||||||
!~results[pluginName].description.toLowerCase().indexOf(searchTerm))
|
!~results[pluginName].description.toLowerCase().indexOf(searchTerm))
|
||||||
) {
|
) {
|
||||||
if (typeof results[pluginName].description === 'undefined') {
|
if (typeof results[pluginName].description === 'undefined') {
|
||||||
console.debug('plugin without Description: %s', results[pluginName].name);
|
logger.debug(`plugin without Description: ${results[pluginName].name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -2,12 +2,15 @@
|
||||||
|
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const hooks = require('./hooks');
|
const hooks = require('./hooks');
|
||||||
|
const log4js = require('log4js');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const runNpm = require('../../../node/utils/run_npm');
|
const runNpm = require('../../../node/utils/run_npm');
|
||||||
const tsort = require('./tsort');
|
const tsort = require('./tsort');
|
||||||
const pluginUtils = require('./shared');
|
const pluginUtils = require('./shared');
|
||||||
const defs = require('./plugin_defs');
|
const defs = require('./plugin_defs');
|
||||||
|
|
||||||
|
const logger = log4js.getLogger('plugins');
|
||||||
|
|
||||||
exports.prefix = 'ep_';
|
exports.prefix = 'ep_';
|
||||||
|
|
||||||
exports.formatPlugins = () => Object.keys(defs.plugins).join(', ');
|
exports.formatPlugins = () => Object.keys(defs.plugins).join(', ');
|
||||||
|
@ -55,8 +58,11 @@ exports.update = async () => {
|
||||||
const plugins = {};
|
const plugins = {};
|
||||||
|
|
||||||
// Load plugin metadata ep.json
|
// Load plugin metadata ep.json
|
||||||
await Promise.all(Object.keys(packages).map(
|
await Promise.all(Object.keys(packages).map(async (pluginName) => {
|
||||||
async (pluginName) => await loadPlugin(packages, pluginName, plugins, parts)));
|
logger.info(`Loading plugin ${pluginName}...`);
|
||||||
|
await loadPlugin(packages, pluginName, plugins, parts);
|
||||||
|
}));
|
||||||
|
logger.info(`Loaded ${Object.keys(packages).length} plugins`);
|
||||||
|
|
||||||
defs.plugins = plugins;
|
defs.plugins = plugins;
|
||||||
defs.parts = sortParts(parts);
|
defs.parts = sortParts(parts);
|
||||||
|
@ -66,6 +72,7 @@ exports.update = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getPackages = async () => {
|
exports.getPackages = async () => {
|
||||||
|
logger.info('Running npm to get a list of installed plugins...');
|
||||||
// Note: Do not pass `--prod` because it does not work if there is no package.json.
|
// Note: Do not pass `--prod` because it does not work if there is no package.json.
|
||||||
const np = runNpm(['ls', '--long', '--json', '--depth=0'], {
|
const np = runNpm(['ls', '--long', '--json', '--depth=0'], {
|
||||||
stdoutLogger: null, // We want to capture stdout, so don't attempt to log it.
|
stdoutLogger: null, // We want to capture stdout, so don't attempt to log it.
|
||||||
|
@ -104,11 +111,11 @@ const loadPlugin = async (packages, pluginName, plugins, parts) => {
|
||||||
part.full_name = `${pluginName}/${part.name}`;
|
part.full_name = `${pluginName}/${part.name}`;
|
||||||
parts[part.full_name] = part;
|
parts[part.full_name] = part;
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (err) {
|
||||||
console.error(`Unable to parse plugin definition file ${pluginPath}: ${ex.toString()}`);
|
logger.error(`Unable to parse plugin definition file ${pluginPath}: ${err.stack || err}`);
|
||||||
}
|
}
|
||||||
} catch (er) {
|
} catch (err) {
|
||||||
console.error(`Unable to load plugin definition file ${pluginPath}`);
|
logger.error(`Unable to load plugin definition file ${pluginPath}: ${err.stack || err}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue