Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/prettystream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ var util = require('util');
var format = util.format;
var http = require('http');

var moment = require('moment');
moment().format();

var colors = {
'bold' : [1, 22],
'italic' : [3, 23],
Expand All @@ -23,7 +26,9 @@ var colors = {

var defaultOptions = {
mode: 'long', //short, long, dev
useColor: true
useColor: true,
UTC: true,
timeFormat: moment.defaultFormat
};

var levelFromName = {
Expand Down Expand Up @@ -101,9 +106,12 @@ function PrettyStream(opts){
}

function extractTime(rec){
var time = (typeof rec.time === 'object') ? rec.time.toISOString() : rec.time;

if ((config.mode === 'short' || config.mode === 'dev') && time[10] == 'T') {
var time = (config.UTC) ? moment(time).utc() : moment(time);

if (time.isValid()) time = time.format(config.timeFormat);
else time = (typeof rec.time === 'object') ? rec.time.toISOString() : rec.time;

if ((config.mode === 'short' || config.mode === 'dev') && time[10] == 'T' && config.timeFormat == defaultOptions.timeFormat) {
return stylize(time.substr(11));
}
return stylize(time);
Expand Down
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
"type": "git",
"url": "git://github.com/mrrama/node-bunyan-prettystream.git"
},
"engines": ["node >=0.8.0"],
"engines": { "node": ">=0.8.0" },
"keywords": ["log", "logging", "console", "bunyan", "development", "stream"],

"dependencies": {
"moment": "~2.8"
},

"devDependencies": {
"mocha": "1.11.0",
"blanket" : "1.1.5",
"mocha-lcov-reporter" : "0.0.1",
"blanket": "1.1.5",
"mocha-lcov-reporter": "0.0.1",
"coveralls": "2.0.13",
"travis-cov": "0.2.4",
"should": "1.2.2"
Expand All @@ -25,4 +29,4 @@
"test": "make test",
"travis-cov": { "threshold": 70 }
}
}
}
24 changes: 24 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ This library is only really meant for development and should not be used on prod
});
```

# Options

```javascript
var prettyStdOut = new PrettyStream({
mode: 'long', //short, long, dev
useColor: true,
UTC: true,
timeFormat: moment.defaultFormat // "2014-11-10T23:35:25+00:00" (ISO 8601)
});
```

`UTC` defaults to `true`, while setting `false` will use the machine's local time zone.

`timeFormat` uses [moment.js conventions](http://momentjs.com/docs/#/displaying/format/) and defaults to ISO 8601 format.

Custom time formatting example:

```javascript
var prettyStdOut = new PrettyStream({
UTC: false,
timeFormat: 'YYYY-MM-DD HH:mm:ssZZ' // "2014-11-10 14:47:32-0800"
});
```

# Tests

Running unit tests requires `mocha` installed.
Expand Down