Skip to content

Commit

Permalink
Feat: supporting a custom logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Mar 1, 2024
1 parent 98028e9 commit 7e186bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const busboy = require('busboy'); // eslint-disable-line no-unused-vars

const DEFAULT_OPTIONS = {
debug: false,
logger: undefined,
uploadTimeout: 60000,
fileHandler: false,
uriDecodeFileNames: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let tempCounter = 0;
const debugLog = (options, msg) => {
const opts = options || {};
if (!opts.debug) return false;
console.log(`Express-file-upload: ${msg}`); // eslint-disable-line
(opts.logger || console).log(`Express-file-upload: ${msg}`);
return true;
};

Expand Down
10 changes: 10 additions & 0 deletions test/utilities.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ describe('utilities: Test of the utilities functions', function() {
assert.equal(debugLog({debug: true}, testMessage), true);
});

it('supports a custom logger', () => {
const calls = [];
const logger = {
log: (...args) => calls.push(args)
};
debugLog({debug: true, logger}, testMessage);
assert.equal(calls.length, 1);
assert.deepEqual(calls[0], [`Express-file-upload: ${testMessage}`]);
});

});
//isFunc tests
describe('Test isFunc function', () => {
Expand Down

0 comments on commit 7e186bd

Please sign in to comment.