added unit testing, and started implementing unit tests...phew

This commit is contained in:
Josh Burman
2019-03-12 22:28:02 -04:00
parent 74aad4a957
commit e8c2539f1b
3489 changed files with 464813 additions and 88 deletions

14
node_modules/logform/examples/combine.js generated vendored Normal file
View File

@ -0,0 +1,14 @@
const { format } = require('../');
const { combine, timestamp, label } = format;
const labelTimestamp = combine(
label({ label: 'right meow!' }),
timestamp()
);
const info = labelTimestamp.transform({
level: 'info',
message: 'What time is the testing at?'
});
console.dir(info);

30
node_modules/logform/examples/filter.js generated vendored Normal file
View File

@ -0,0 +1,30 @@
/* eslint no-unused-vars: 0 */
const { format } = require('../');
const { combine, timestamp, label } = format;
const ignorePrivate = format((info, opts) => {
if (info.private) { return false; }
return info;
})();
console.dir(ignorePrivate.transform({
level: 'error',
message: 'Public error to share'
}));
console.dir(ignorePrivate.transform({
level: 'error',
private: true,
message: 'This is super secret - hide it.'
}));
const willNeverThrow = format.combine(
format(info => { return false; })(), // Ignores everything
format(info => { throw new Error('Never reached'); })()
);
console.dir(willNeverThrow.transform({
level: 'info',
message: 'wow such testing'
}));

6
node_modules/logform/examples/invalid.js generated vendored Normal file
View File

@ -0,0 +1,6 @@
/* eslint no-unused-vars: 0 */
const { format } = require('../');
const invalid = format(function invalid(just, too, many, args) {
return just;
});

78
node_modules/logform/examples/metadata.js generated vendored Normal file
View File

@ -0,0 +1,78 @@
const { format } = require('../');
const { combine, json, metadata, timestamp } = format;
// Default Functionality (no options passed)
const defaultFormatter = combine(
timestamp(),
metadata(),
json()
);
const defaultMessage = defaultFormatter.transform({
level: 'info',
message: 'This should be a message.',
application: 'Microsoft Office',
store: 'Big Box Store',
purchaseAmount: '9.99'
});
console.dir(defaultMessage);
// Fill all keys into metadata except those provided
const formattedLogger = combine(
timestamp(),
metadata({ fillExcept: ['message', 'level', 'timestamp'] }),
json()
);
const fillExceptMessage = formattedLogger.transform({
level: 'info',
message: 'This should have attached metadata',
category: 'movies',
subCategory: 'action'
});
console.dir(fillExceptMessage);
// Fill only the keys provided into the object, and also give it a different key
const customMetadataLogger = combine(
timestamp(),
metadata({ fillWith: ['publisher', 'author', 'book'], key: 'bookInfo' }),
json()
);
const fillWithMessage = customMetadataLogger.transform({
level: 'debug',
message: 'This message should be outside of the bookInfo object',
publisher: 'Lorem Press',
author: 'Albert Einstein',
book: '4D Chess for Dummies',
label: 'myCustomLabel'
});
console.dir(fillWithMessage);
// Demonstrates Metadata 'chaining' to combine multiple datapoints.
const chainedMetadata = combine(
timestamp(),
metadata({ fillWith: ['publisher', 'author', 'book'], key: 'bookInfo' }),
metadata({ fillWith: ['purchasePrice', 'purchaseDate', 'transactionId'], key: 'transactionInfo' }),
metadata({ fillExcept: ['level', 'message', 'label', 'timestamp'] }),
json()
);
const chainedMessage = chainedMetadata.transform({
level: 'debug',
message: 'This message should be outside of the bookInfo object',
publisher: 'Lorem Press',
author: 'Albert Einstein',
book: '4D Chess for Dummies',
label: 'myCustomLabel',
purchasePrice: '9.99',
purchaseDate: '2.10.2018',
transactionId: '123ABC'
});
console.dir(chainedMessage);

39
node_modules/logform/examples/padLevels.js generated vendored Normal file
View File

@ -0,0 +1,39 @@
const { format } = require('../');
const { combine, padLevels, simple } = format;
const { MESSAGE } = require('triple-beam');
const paddedFormat = combine(
padLevels({
// Uncomment for a custom filler for the padding, defaults to ' '.
// filler: 'foo',
// Levels has to be defined, same as `winston.createLoggers({ levels })`.
levels: {
error: 0,
warn: 1,
info: 2,
http: 3,
verbose: 4,
debug: 5,
silly: 6
}
}),
simple()
);
const info = paddedFormat.transform({
level: 'info',
message: 'This is an info level message.'
});
const error = paddedFormat.transform({
level: 'error',
message: 'This is an error level message.'
});
const verbose = paddedFormat.transform({
level: 'verbose',
message: 'This is a verbose level message.'
});
console.dir(info[MESSAGE]);
console.dir(error[MESSAGE]);
console.dir(verbose[MESSAGE]);

25
node_modules/logform/examples/volume.js generated vendored Normal file
View File

@ -0,0 +1,25 @@
const { format } = require('../');
const volume = format((info, opts) => {
if (opts.yell) {
info.message = info.message.toUpperCase();
} else if (opts.whisper) {
info.message = info.message.toLowerCase();
}
return info;
});
// `volume` is now a function that returns instances of the format.
const scream = volume({ yell: true });
console.dir(scream.transform({
level: 'info',
message: `sorry for making you YELL in your head!`
}, scream.options));
// `volume` can be used multiple times to create different formats.
const whisper = volume({ whisper: true });
console.dir(whisper.transform({
level: 'info',
message: `WHY ARE THEY MAKING US YELL SO MUCH!`
}, whisper.options));