diff --git a/client.js b/client.js index 8a578fa..b6bf1a7 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 c32f234..c8302db 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/docs/constructor.md b/docs/constructor.md index eb1dc04..a10b36d 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/off debugging and extra logging to console, or pass your own function to handle debug messages on your own false diff --git a/server.js b/server.js index b6ed555..d5eeb48 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/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` @@ -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; }