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', permission: 'user',
primary: true, primary: true,
action: function(params, options, done) { action: function(params, options, done) {
var _, promise, resin; var _, moment, printLine, promise, resin;
_ = require('lodash'); _ = require('lodash');
resin = require('resin-sdk'); resin = require('resin-sdk');
promise = resin.logs.history(params.uuid).each(function(line) { moment = require('moment');
return console.log(line.message); 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) { if (!options.tail) {
return promise["catch"](done)["finally"](function() { return promise["catch"](done)["finally"](function() {
return process.exit(0); return process.exit(0);
@ -27,9 +31,7 @@
} }
return promise.then(function() { return promise.then(function() {
return resin.logs.subscribe(params.uuid).then(function(logs) { return resin.logs.subscribe(params.uuid).then(function(logs) {
logs.on('line', function(line) { logs.on('line', printLine);
return console.log(line.message);
});
return logs.on('error', done); return logs.on('error', done);
}); });
})["catch"](done); })["catch"](done);

View File

@ -30,9 +30,13 @@ module.exports =
action: (params, options, done) -> action: (params, options, done) ->
_ = require('lodash') _ = require('lodash')
resin = require('resin-sdk') resin = require('resin-sdk')
moment = require('moment')
promise = resin.logs.history(params.uuid).each (line) -> printLine = (line) ->
console.log(line.message) 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 if not options.tail
@ -44,7 +48,6 @@ module.exports =
promise.then -> promise.then ->
resin.logs.subscribe(params.uuid).then (logs) -> resin.logs.subscribe(params.uuid).then (logs) ->
logs.on 'line', (line) -> logs.on('line', printLine)
console.log(line.message)
logs.on('error', done) logs.on('error', done)
.catch(done) .catch(done)

View File

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