From 517af98bde940d3ec5bc14d54e3ccc2b5b431e3a Mon Sep 17 00:00:00 2001 From: mAAdhaTTah Date: Wed, 27 Mar 2019 23:53:28 -0400 Subject: [PATCH] Add configurable logger This allows calling code to configure where log messages go. Fixes #38. --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 22fe358..83cbd3e 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ const path = require('path'); function CaseSensitivePathsPlugin(options) { this.options = options || {}; + this.logger = this.options.logger || console; this.reset(); } @@ -51,13 +52,13 @@ CaseSensitivePathsPlugin.prototype.getFilenamesInDir = function (dir, callback) return; } if (this.options.debug) { - console.log('[CaseSensitivePathsPlugin] Reading directory', dir); + this.logger.log('[CaseSensitivePathsPlugin] Reading directory', dir); } fs.readdir(dir, (err, files) => { if (err) { if (that.options.debug) { - console.log('[CaseSensitivePathsPlugin] Failed to read directory', dir, err); + this.logger.log('[CaseSensitivePathsPlugin] Failed to read directory', dir, err); } callback([]); return; @@ -136,7 +137,7 @@ CaseSensitivePathsPlugin.prototype.apply = function (compiler) { const onDone = () => { if (this.options.debug) { - console.log('[CaseSensitivePathsPlugin] Total filesystem reads:', this.fsOperations); + this.logger.log('[CaseSensitivePathsPlugin] Total filesystem reads:', this.fsOperations); } this.reset(); @@ -171,7 +172,7 @@ CaseSensitivePathsPlugin.prototype.apply = function (compiler) { compiler.hooks.done.tap('CaseSensitivePathsPlugin', onDone); if (this.options.useBeforeEmitHook) { if (this.options.debug) { - console.log('[CaseSensitivePathsPlugin] Using the hook for before emit.'); + this.logger.log('[CaseSensitivePathsPlugin] Using the hook for before emit.'); } compiler.hooks.emit.tapAsync('CaseSensitivePathsPlugin', (compilation, callback) => { let resolvedFilesCount = 0;