Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add support for format strings.

  • Loading branch information...
commit 4dd07e3b8fbf74bbc8f4d0af23237c06bea4ea19 1 parent eee5928
Tomaz Muraus authored

Showing 1 changed file with 16 additions and 2 deletions. Show diff stats Hide diff stats

  1. +16 2 lib/logmagic.js
18 lib/logmagic.js
@@ -71,6 +71,20 @@ function buildLogMethod(level, callback) {
71 71 }
72 72 }
73 73
  74 +function applyFormatting(message, obj) {
  75 + function replaceFunction(str, p1) {
  76 + if (obj.hasOwnProperty(p1)) {
  77 + return obj[p1];
  78 + }
  79 +
  80 + return p1;
  81 + }
  82 +
  83 + var regex = new RegExp(/\$\{(.*?)\}/g);
  84 + message = message.replace(regex, replaceFunction);
  85 + return message;
  86 +}
  87 +
74 88 function nullLogger() {
75 89 /* Intentionally blank. */
76 90 }
@@ -170,8 +184,8 @@ exports.route = function(match, loglevel, sinkname) {
170 184 /* This is just here for initial dev work, REMOVE ME */
171 185 exports.registerSink("console", function(level, message, obj) {
172 186 if (obj) {
173   - /* TODO: improve */
174   - console.log(message + " " + JSON.stringify(obj));
  187 + message = applyFormatting(message, obj);
  188 + console.log(message);
175 189 }
176 190 else {
177 191 console.log(message);

0 comments on commit 4dd07e3

Please sign in to comment.
Something went wrong with that request. Please try again.