[Pkg-javascript-commits] [node-debuglog] 01/05: Import Upstream version 1.0.1
Saravanan Palanisamy
saravanan30erd-guest at moszumanska.debian.org
Tue Jun 27 08:23:10 UTC 2017
This is an automated email from the git hooks/post-receive script.
saravanan30erd-guest pushed a commit to branch master
in repository node-debuglog.
commit 46d0d44f9f6e76fbea5c6faf021dd69db0352bb8
Author: saravanan30erd <saravanan30erd at gmail.com>
Date: Mon Jun 26 09:30:13 2017 -0400
Import Upstream version 1.0.1
---
LICENSE | 19 +++++++++++++++++++
README.md | 40 ++++++++++++++++++++++++++++++++++++++++
debuglog.js | 22 ++++++++++++++++++++++
package.json | 21 +++++++++++++++++++++
4 files changed, 102 insertions(+)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..a3187cc
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright Joyent, Inc. and other Node contributors. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..dc6fcce
--- /dev/null
+++ b/README.md
@@ -0,0 +1,40 @@
+# debuglog - backport of util.debuglog() from node v0.11
+
+To facilitate using the `util.debuglog()` function that will be available when
+node v0.12 is released now, this is a copy extracted from the source.
+
+## require('debuglog')
+
+Return `util.debuglog`, if it exists, otherwise it will return an internal copy
+of the implementation from node v0.11.
+
+## debuglog(section)
+
+* `section` {String} The section of the program to be debugged
+* Returns: {Function} The logging function
+
+This is used to create a function which conditionally writes to stderr
+based on the existence of a `NODE_DEBUG` environment variable. If the
+`section` name appears in that environment variable, then the returned
+function will be similar to `console.error()`. If not, then the
+returned function is a no-op.
+
+For example:
+
+```javascript
+var debuglog = util.debuglog('foo');
+
+var bar = 123;
+debuglog('hello from foo [%d]', bar);
+```
+
+If this program is run with `NODE_DEBUG=foo` in the environment, then
+it will output something like:
+
+ FOO 3245: hello from foo [123]
+
+where `3245` is the process id. If it is not run with that
+environment variable set, then it will not print anything.
+
+You may separate multiple `NODE_DEBUG` environment variables with a
+comma. For example, `NODE_DEBUG=fs,net,tls`.
diff --git a/debuglog.js b/debuglog.js
new file mode 100644
index 0000000..748fd72
--- /dev/null
+++ b/debuglog.js
@@ -0,0 +1,22 @@
+var util = require('util');
+
+module.exports = (util && util.debuglog) || debuglog;
+
+var debugs = {};
+var debugEnviron = process.env.NODE_DEBUG || '';
+
+function debuglog(set) {
+ set = set.toUpperCase();
+ if (!debugs[set]) {
+ if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
+ var pid = process.pid;
+ debugs[set] = function() {
+ var msg = util.format.apply(exports, arguments);
+ console.error('%s %d: %s', set, pid, msg);
+ };
+ } else {
+ debugs[set] = function() {};
+ }
+ }
+ return debugs[set];
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..e51ecc9
--- /dev/null
+++ b/package.json
@@ -0,0 +1,21 @@
+{
+ "name": "debuglog",
+ "version": "1.0.1",
+ "description": "backport of util.debuglog from node v0.11",
+ "license": "MIT",
+ "main": "debuglog.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/sam-github/node-debuglog.git"
+ },
+ "author": {
+ "name": "Sam Roberts",
+ "email": "sam at strongloop.com"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "browser": {
+ "util": false
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-debuglog.git
More information about the Pkg-javascript-commits
mailing list