Skip to content

Commit

Permalink
minor tweaks to log format
Browse files Browse the repository at this point in the history
  • Loading branch information
avital committed May 29, 2013
1 parent 48c1b9b commit 34157eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 5 additions & 8 deletions packages/logging/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,21 @@ Log.format = function (obj, options) {

var appInfo = '';
if (appName) appInfo += appName;
if (originApp && originApp !== appName) appInfo += ':' + originApp;
if (appInfo) appInfo = ' [' + appInfo + ']';
if (originApp && originApp !== appName) appInfo += ' via ' + originApp;
if (appInfo) appInfo = '[' + appInfo + '] ';

var sourceInfo = (file && lineNumber) ?
['(', (program ? program + ':' : ''), file, ':', lineNumber, ')'].join('')
['(', (program ? program + ':' : ''), file, ':', lineNumber, ') '].join('')
: '';
if (sourceInfo && !appInfo)
sourceInfo = ' ' + sourceInfo;

var stderrIndicator = stderr ? ' (STDERR)' : '';
var stderrIndicator = stderr ? '(STDERR) ' : '';

var metaPrefix = [
level.charAt(0).toUpperCase(),
dateStamp,
'-',
timeStamp,
timeInexact ? '?' : '',
timeInexact ? '?' : ' ',
appInfo,
sourceInfo,
stderrIndicator].join('');
Expand All @@ -215,7 +213,6 @@ Log.format = function (obj, options) {
};

return prettify(metaPrefix, META_COLOR)
+ ' '
+ prettify(message, LEVEL_COLORS[level]);
};

Expand Down
6 changes: 3 additions & 3 deletions packages/logging/logging_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Tinytest.add("logging - format", function (test) {

test.equal(
Log.format({message: "message", time: time, timeInexact: true, level: level}),
level.charAt(0).toUpperCase() + "20120908-07:06:05.004? message");
level.charAt(0).toUpperCase() + "20120908-07:06:05.004?message");

test.equal(
Log.format({foo1: "bar1", foo2: "bar2", time: time, level: level}),
Expand All @@ -89,7 +89,7 @@ Tinytest.add("logging - format", function (test) {
// Has everything except stderr field
test.equal(
Log.format({message: "message", foo: "bar", time: time, level: level, file: "app.js", line:42, app: "myApp", originApp: "proxy", program: "server"}),
level.charAt(0).toUpperCase() + '20120908-07:06:05.004 [myApp:proxy](server:app.js:42) message {\"foo\":\"bar\"}');
level.charAt(0).toUpperCase() + '20120908-07:06:05.004 [myApp via proxy] (server:app.js:42) message {\"foo\":\"bar\"}');

// stderr
test.equal(
Expand All @@ -102,7 +102,7 @@ Tinytest.add("logging - format", function (test) {
level.charAt(0).toUpperCase() + '20120908-07:06:05.004 [app] message');
test.equal(
Log.format({message: "message", time: time, level: level, app: "app", originApp: "proxy"}),
level.charAt(0).toUpperCase() + '20120908-07:06:05.004 [app:proxy] message');
level.charAt(0).toUpperCase() + '20120908-07:06:05.004 [app via proxy] message');

// source info
test.equal(
Expand Down

0 comments on commit 34157eb

Please sign in to comment.