From 26e3cb79573834a7d188ec0511e7ff99534d2b4c Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 11 Dec 2015 20:28:29 -0400 Subject: [PATCH] Add timestamp to logs lines --- build/actions/logs.js | 16 +++++++++------- lib/actions/logs.coffee | 11 +++++++---- package.json | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/build/actions/logs.js b/build/actions/logs.js index 421f5ca2..2342783e 100644 --- a/build/actions/logs.js +++ b/build/actions/logs.js @@ -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); diff --git a/lib/actions/logs.coffee b/lib/actions/logs.coffee index c89e9359..2f6e523d 100644 --- a/lib/actions/logs.coffee +++ b/lib/actions/logs.coffee @@ -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) diff --git a/package.json b/package.json index efdaedbb..241aed5b 100644 --- a/package.json +++ b/package.json @@ -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",