From bb4ab4f1687ed0d94acc62a9999e1c08d3f49b5e Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Tue, 12 Oct 2021 21:57:29 +0200 Subject: [PATCH 1/3] plugins: add Logger interface Plugins need to be able to log messasages, say for errors. --- src/plugins/packages/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/packages/index.js b/src/plugins/packages/index.js index ea1ed2cd..47b9e7fb 100644 --- a/src/plugins/packages/index.js +++ b/src/plugins/packages/index.js @@ -47,6 +47,12 @@ const packageApis = function (packageInfo) { Config: { getConfig: () => Helper.config, }, + Logger: { + error: (...args) => log.error(...args), + warn: (...args) => log.warn(...args), + info: (...args) => log.info(...args), + debug: (...args) => log.debug(...args), + }, }; }; From 02ccbc1f69ee984b3ce285065a303abb8400f82e Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Tue, 12 Oct 2021 22:48:47 +0200 Subject: [PATCH 2/3] plugins: expose persistant data dir Plugins need to be able to store persistant files, say settings or databases or similar things. Expose a standard location that gets created when the path is accessed. --- src/plugins/packages/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/packages/index.js b/src/plugins/packages/index.js index 47b9e7fb..a0edeb11 100644 --- a/src/plugins/packages/index.js +++ b/src/plugins/packages/index.js @@ -46,6 +46,7 @@ const packageApis = function (packageInfo) { }, Config: { getConfig: () => Helper.config, + getPersistentStorageDir: getPersistentStorageDir.bind(this, packageInfo.packageName), }, Logger: { error: (...args) => log.error(...args), @@ -87,6 +88,12 @@ function getEnabledPackages(packageJson) { return []; } +function getPersistentStorageDir(packageName) { + const dir = path.join(Helper.getPackagesPath(), packageName); + fs.mkdirSync(dir, {recursive: true}); // we don't care if it already exists or not + return dir; +} + function loadPackage(packageName) { let packageInfo; let packageFile; From 1e896a967230c27c60d9c616a5ec4f7e94140c48 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Wed, 13 Oct 2021 23:39:32 +0200 Subject: [PATCH 3/3] plugins: prefix logger with the plugin name --- src/plugins/packages/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/packages/index.js b/src/plugins/packages/index.js index a0edeb11..6db96280 100644 --- a/src/plugins/packages/index.js +++ b/src/plugins/packages/index.js @@ -49,10 +49,10 @@ const packageApis = function (packageInfo) { getPersistentStorageDir: getPersistentStorageDir.bind(this, packageInfo.packageName), }, Logger: { - error: (...args) => log.error(...args), - warn: (...args) => log.warn(...args), - info: (...args) => log.info(...args), - debug: (...args) => log.debug(...args), + error: (...args) => log.error(`[${packageInfo.packageName}]`, ...args), + warn: (...args) => log.warn(`[${packageInfo.packageName}]`, ...args), + info: (...args) => log.info(`[${packageInfo.packageName}]`, ...args), + debug: (...args) => log.debug(`[${packageInfo.packageName}]`, ...args), }, }; };