From e49448e13e943cf9470ce2fb8ceb651699ab36b8 Mon Sep 17 00:00:00 2001 From: jankapunkt Date: Tue, 25 Nov 2025 12:48:10 +0100 Subject: [PATCH 1/4] feature(server/client): allow debug paramter to be a function for custom logging --- client.js | 4 ++-- core.js | 4 +++- server.js | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/client.js b/client.js index 8a578fab..b6bf1a75 100644 --- a/client.js +++ b/client.js @@ -14,7 +14,7 @@ const allowedParams = ['allowClientCode', 'allowQueryStringCookies', 'chunkSize' * @locus Client * @class FilesCollection * @param config {FilesCollectionConfig} - [anywhere] configuration object with the following properties: - * @param config.debug {boolean} - [anywhere] turn on/off debugging and extra logging + * @param config.debug {boolean|function} - [anywhere] Turn on/of debugging and extra logging to console, or pass your own function to handle debug messages on your own * @param config.ddp {DDP.DDPStatic} - [client] custom DDP connection; object returned from `DDP.connect()` * @param config.schema {object} - [anywhere] collection schema * @param config.public {boolean} - [anywhere] store files in folder accessible for proxy servers, for limits, etc. @@ -48,7 +48,7 @@ class FilesCollection extends FilesCollectionCore { allowQueryStringCookies: this.allowQueryStringCookies, }); - if (!helpers.isBoolean(this.debug)) { + if (!helpers.isBoolean(this.debug) && !helpers.isFunction(this.debug)) { this.debug = false; } diff --git a/core.js b/core.js index c32f234d..c8302dbb 100644 --- a/core.js +++ b/core.js @@ -104,8 +104,10 @@ export default class FilesCollectionCore extends EventEmitter { */ _debug(...args) { if (this.debug) { + // if debug is truthy but not true it should be a function + const debugFn = this.debug === true ? null : this.debug; // eslint-disable-next-line no-console - (console.info || console.log || function () {}).apply(undefined, args); + (debugFn || console.info || console.log || function () {}).apply(undefined, args); } } diff --git a/server.js b/server.js index b6ed5559..cf28627c 100644 --- a/server.js +++ b/server.js @@ -73,7 +73,7 @@ const createIndex = async (_collection, keys, opts) => { * @locus Server * @class FilesCollection * @param config {FilesCollectionConfig} - [Both] Configuration object with next properties: - * @param config.debug {boolean} - [Both] Turn on/of debugging and extra logging + * @param config.debug {boolean|function} - [Both] Turn on/of debugging and extra logging to console, or pass your own function to handle debug messages on your own * @param config.schema {Object} - [Both] Collection Schema * @param config.public {boolean} - [Both] Store files in folder accessible for proxy servers, for limits, and more - read docs * @param config.strict {boolean} - [Server] Strict mode for partial content, if is `true` server will return `416` response code, when `range` is not specified, otherwise server return `206` @@ -161,7 +161,7 @@ class FilesCollection extends FilesCollectionCore { const self = this; - if (!helpers.isBoolean(this.debug)) { + if (!helpers.isBoolean(this.debug) && !helpers.isFunction(this.debug)) { this.debug = false; } From 87a862ebf8d5c6d9689bb12d71ba82f59e0af232 Mon Sep 17 00:00:00 2001 From: jankapunkt Date: Tue, 25 Nov 2025 12:49:29 +0100 Subject: [PATCH 2/4] docs: update constructor description for debug parameter --- docs/constructor.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/constructor.md b/docs/constructor.md index eb1dc04a..495878e7 100644 --- a/docs/constructor.md +++ b/docs/constructor.md @@ -639,13 +639,13 @@ - config.debug {Boolean} + config.debug {Boolean|Function} Isomorphic - Turn on/of debugging and extra logging + Turn on/of debugging and extra logging to console, or pass your own function to handle debug messages on your own false From 7024b9ca89fe17018e0432940b455bc0ce679226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=BCster?= Date: Tue, 25 Nov 2025 13:05:00 +0100 Subject: [PATCH 3/4] fix(server): fix minor typo in server.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index cf28627c..d5eeb483 100644 --- a/server.js +++ b/server.js @@ -73,7 +73,7 @@ const createIndex = async (_collection, keys, opts) => { * @locus Server * @class FilesCollection * @param config {FilesCollectionConfig} - [Both] Configuration object with next properties: - * @param config.debug {boolean|function} - [Both] Turn on/of debugging and extra logging to console, or pass your own function to handle debug messages on your own + * @param config.debug {boolean|function} - [Both] Turn on/off debugging and extra logging to console, or pass your own function to handle debug messages on your own * @param config.schema {Object} - [Both] Collection Schema * @param config.public {boolean} - [Both] Store files in folder accessible for proxy servers, for limits, and more - read docs * @param config.strict {boolean} - [Server] Strict mode for partial content, if is `true` server will return `416` response code, when `range` is not specified, otherwise server return `206` From b25b9f1a2b4be89dc5b3163a341625ff302e9d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=BCster?= Date: Tue, 25 Nov 2025 13:05:30 +0100 Subject: [PATCH 4/4] fix(dcs): correct minor typo in constructor.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/constructor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/constructor.md b/docs/constructor.md index 495878e7..a10b36d7 100644 --- a/docs/constructor.md +++ b/docs/constructor.md @@ -645,7 +645,7 @@ Isomorphic - Turn on/of debugging and extra logging to console, or pass your own function to handle debug messages on your own + Turn on/off debugging and extra logging to console, or pass your own function to handle debug messages on your own false