diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2011-12-14 13:28:51 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-12-14 13:36:21 +0100 |
commit | 97900776bb3611877d126aa58743eb9b5b2a4be8 (patch) | |
tree | cd1598db53572e96db21f14c7978aa204bfc5620 | |
parent | d29be0dfa2e06ee55ce65e440aba5f36f21d23a2 (diff) | |
download | node-97900776bb3611877d126aa58743eb9b5b2a4be8.tar.gz |
util: add internal function _deprecationWarning()
-rw-r--r-- | lib/os.js | 8 | ||||
-rw-r--r-- | lib/sys.js | 11 | ||||
-rw-r--r-- | lib/util.js | 16 |
3 files changed, 20 insertions, 15 deletions
@@ -37,12 +37,8 @@ exports.platform = function() { return process.platform; }; -var warnNetworkInterfaces = true; exports.getNetworkInterfaces = function() { - if (warnNetworkInterfaces) { - console.error("os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()"); - console.trace(); - warnNetworkInterfaces = false; - } + require('util')._deprecationWarning('os', + 'os.getNetworkInterfaces() is deprecated - use os.networkInterfaces()'); return exports.networkInterfaces(); }; diff --git a/lib/sys.js b/lib/sys.js index d53a3dd95..0039b89d2 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -21,15 +21,8 @@ var util = require('util'); -var sysWarning; -if (!sysWarning) { - sysWarning = 'The "sys" module is now called "util". ' + - 'It should have a similar interface.'; - if (process.env.NODE_DEBUG && process.env.NODE_DEBUG.indexOf('sys') != -1) - console.trace(sysWarning); - else - console.error(sysWarning); -} +util._deprecationWarning('sys', + 'The "sys" module is now called "util". It should have a similar interface.'); exports.print = util.print; exports.puts = util.puts; diff --git a/lib/util.js b/lib/util.js index b00da2de9..cd4cc0e96 100644 --- a/lib/util.js +++ b/lib/util.js @@ -518,3 +518,19 @@ exports.inherits = function(ctor, superCtor) { } }); }; + +var deprecationWarnings; + +exports._deprecationWarning = function(moduleId, message) { + if (!deprecationWarnings) + deprecationWarnings = {}; + else if (message in deprecationWarnings) + return; + + deprecationWarnings[message] = true; + + if ((new RegExp('\\b' + moduleId + '\\b')).test(process.env.NODE_DEBUG)) + console.trace(message); + else + console.error(message); +}; |