Skip to content

Commit

Permalink
Add configurable logger
Browse files Browse the repository at this point in the history
This allows calling code to configure where log messages go.

Fixes #38.
  • Loading branch information
mAAdhaTTah authored and Urthen committed Apr 3, 2019
1 parent 90eb443 commit 517af98
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const path = require('path');

function CaseSensitivePathsPlugin(options) {
this.options = options || {};
this.logger = this.options.logger || console;
this.reset();
}

Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 517af98

Please sign in to comment.