[Pkg-javascript-commits] [node-ain2] 33/102: fixed objects logging (latest version of 'format' function from nodejs sources)

Jonas Smedegaard js at moszumanska.debian.org
Tue Apr 29 11:59:47 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-ain2.

commit 89e00dd6002ed5a4afb122ab9f450aaf3ca38d38
Author: Beresta <berestnev at gmail.com>
Date:   Sun Sep 25 17:33:54 2011 +0400

    fixed objects logging (latest version of 'format' function from nodejs sources)
---
 index.js | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/index.js b/index.js
index 6396939..efbc21a 100644
--- a/index.js
+++ b/index.js
@@ -44,27 +44,34 @@ var formatRegExp = /%[sdj]/g;
  * @returns
  */
 function format(f) {
+  var util = require('util');
+
   if (typeof f !== 'string') {
-    var objects = [], util = require('util');
+    var objects = [];
     for (var i = 0; i < arguments.length; i++) {
       objects.push(util.inspect(arguments[i]));
     }
     return objects.join(' ');
   }
-  
-  var index = 1;
+
+
+  var i = 1;
   var args = arguments;
   var str = String(f).replace(formatRegExp, function(x) {
     switch (x) {
-      case '%s': return args[index++];
-      case '%d': return +args[index++];
-      case '%j': return JSON.stringify(args[index++]);
+      case '%s': return String(args[i++]);
+      case '%d': return Number(args[i++]);
+      case '%j': return JSON.stringify(args[i++]);
       default:
         return x;
     }
   });
-  for (var len = args.length; index < len; ++index) {
-    str += ' ' + args[index];
+  for (var len = args.length, x = args[i]; i < len; x = args[++i]) {
+    if (x === null || typeof x !== 'object') {
+      str += ' ' + x;
+    } else {
+      str += ' ' + util.inspect(x);
+    }
   }
   return str;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ain2.git



More information about the Pkg-javascript-commits mailing list