Add API for custom handling of deprecations

This commit is contained in:
Max Brunsfeld 2016-02-16 15:09:35 -08:00
parent 175449f096
commit ccef805e9b
5 changed files with 58 additions and 1 deletions

View file

@ -88,9 +88,13 @@ deprecate.warn = function(oldName, newName) {
return deprecate.log(oldName + " is deprecated. Use " + newName + " instead.");
};
var deprecationHandler = null;
// Print deprecation message.
deprecate.log = function(message) {
if (process.throwDeprecation) {
if (typeof deprecationHandler === 'function') {
deprecationHandler(message);
} else if (process.throwDeprecation) {
throw new Error(message);
} else if (process.traceDeprecation) {
return console.trace(message);
@ -99,4 +103,12 @@ deprecate.log = function(message) {
}
};
deprecate.setHandler = function(handler) {
deprecationHandler = handler;
};
deprecate.getHandler = function() {
return deprecationHandler;
}
module.exports = deprecate;