Skip to content

Commit

Permalink
added format function to common.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Jul 23, 2012
1 parent 6c83657 commit 3998d19
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/winston/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.