From 1513932ca10a440272d4a4c29c3414d85d748961 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 21 Feb 2022 03:25:32 -0500 Subject: [PATCH] plugins: Give each plugin a plugin-specific logger object This makes it possible for plugins to stop assuming that log4js is available at `ep_etherpad-lite/node_modules/log4js`. --- CHANGELOG.md | 2 ++ doc/api/hooks_server-side.md | 5 ++++- src/static/js/pluginfw/plugins.js | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bdbf5e1a..8715d5bc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ and whether the user only has read-only access. * The `handleMessageSecurity` server-side hook can now be used to grant write access for the current message only. +* The `init_` server-side hooks have a new `logger` context + property that plugins can use to log messages. ### Compatibility changes diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index 4ee35f920..3e2e6313b 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -56,7 +56,10 @@ Called from: `src/static/js/pluginfw/plugins.js` Run during startup after the named plugin is initialized. -Context properties: None +Context properties: + + * `logger`: An object with the following `console`-like methods: `debug`, + `info`, `log`, `warn`, `error`. ## `expressPreSession` diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index a4a2df40d..ec3cfaa92 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -98,7 +98,10 @@ exports.update = async () => { defs.parts = sortParts(parts); defs.hooks = pluginUtils.extractHooks(defs.parts, 'hooks', exports.pathNormalization); defs.loaded = true; - await Promise.all(Object.keys(defs.plugins).map((p) => hooks.aCallAll(`init_${p}`, {}))); + await Promise.all(Object.keys(defs.plugins).map(async (p) => { + const logger = log4js.getLogger(`plugin:${p}`); + await hooks.aCallAll(`init_${p}`, {logger}); + })); }; exports.getPackages = async () => {