Merge pull request #281 from resin-io/feat/logs-timestamp

Add timestamp to logs lines
This commit is contained in:
Juan Cruz Viotti 2015-12-11 21:26:21 -04:00
commit de9297c351
3 changed files with 17 additions and 11 deletions

View File

@ -14,12 +14,16 @@
permission: 'user',
primary: true,
action: function(params, options, done) {
var _, promise, resin;
var _, moment, printLine, promise, resin;
_ = require('lodash');
resin = require('resin-sdk');
promise = resin.logs.history(params.uuid).each(function(line) {
return console.log(line.message);
});
moment = require('moment');
printLine = function(line) {
var timestamp;
timestamp = moment(line.timestamp).format('DD.MM.YY HH:mm:ss (ZZ)');
return console.log(timestamp + " " + line.message);
};
promise = resin.logs.history(params.uuid).each(printLine);
if (!options.tail) {
return promise["catch"](done)["finally"](function() {
return process.exit(0);
@ -27,9 +31,7 @@
}
return promise.then(function() {
return resin.logs.subscribe(params.uuid).then(function(logs) {
logs.on('line', function(line) {
return console.log(line.message);
});
logs.on('line', printLine);
return logs.on('error', done);
});
})["catch"](done);

View File

@ -30,9 +30,13 @@ module.exports =
action: (params, options, done) ->
_ = require('lodash')
resin = require('resin-sdk')
moment = require('moment')
promise = resin.logs.history(params.uuid).each (line) ->
console.log(line.message)
printLine = (line) ->
timestamp = moment(line.timestamp).format('DD.MM.YY HH:mm:ss (ZZ)')
console.log("#{timestamp} #{line.message}")
promise = resin.logs.history(params.uuid).each(printLine)
if not options.tail
@ -44,7 +48,6 @@ module.exports =
promise.then ->
resin.logs.subscribe(params.uuid).then (logs) ->
logs.on 'line', (line) ->
console.log(line.message)
logs.on('line', printLine)
logs.on('error', done)
.catch(done)

View File

@ -45,6 +45,7 @@
"columnify": "^1.5.2",
"is-root": "^1.0.0",
"lodash": "^3.10.0",
"moment": "^2.10.6",
"nplugm": "^3.0.0",
"president": "^2.0.1",
"prettyjson": "^1.1.3",