Permalink
Browse files

added format function to common.js

  • Loading branch information...
1 parent 6c83657 commit 3998d199c2a0780f98d4c00ddf61091bad1e97fc @fb55 fb55 committed Jul 23, 2012
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/winston/common.js
View
@@ -257,3 +257,22 @@ exports.serialize = function (obj, key) {
return msg;
};
+
+//
+// ### function format (arr)
+// #### @arr {Array} The array that contains all parts of the message
+// similar to util.format
+// returns the formated string
+// uses the original array and removes items as it proceeds
+//
+exports.format = function (arr) {
+ return arr.shift().replace(/%[sdj%]/g, function (x){
+ switch (x.charAt(1)) {
+ case "j": return JSON.stringify(arr.shift());
+ case "s": return String(arr.shift());
+ case "d": return Number(arr.shift());
+ case "%": return "%";
+ default: return x;
+ }
+ });
+};

0 comments on commit 3998d19

Please sign in to comment.