balena-cli/build/actions/logs.js

60 lines
2.2 KiB
JavaScript
Raw Normal View History

// Generated by CoffeeScript 1.12.2
/*
Copyright 2016 Resin.io
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2015-02-26 15:47:56 +00:00
(function() {
module.exports = {
2015-02-26 15:47:56 +00:00
signature: 'logs <uuid>',
description: 'show device logs',
2016-01-21 14:23:40 +00:00
help: 'Use this command to show logs for a specific device.\n\nBy default, the command prints all log messages and exit.\n\nTo continuously stream output, and see new logs in real time, use the `--tail` option.\n\nNote that for now you need to provide the whole UUID for this command to work correctly.\n\nThis is due to some technical limitations that we plan to address soon.\n\nExamples:\n\n $ resin logs 23c73a1\n $ resin logs 23c73a1',
2015-02-26 15:47:56 +00:00
options: [
{
signature: 'tail',
description: 'continuously stream output',
boolean: true,
alias: 't'
}
],
permission: 'user',
primary: true,
2015-02-26 15:47:56 +00:00
action: function(params, options, done) {
2015-12-12 00:28:29 +00:00
var _, moment, printLine, promise, resin;
_ = require('lodash');
2016-12-16 14:34:05 +00:00
resin = require('../resin-sdk');
2015-12-12 00:28:29 +00:00
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);
});
}
return promise.then(function() {
return resin.logs.subscribe(params.uuid).then(function(logs) {
2015-12-12 00:28:29 +00:00
logs.on('line', printLine);
return logs.on('error', done);
});
})["catch"](done);
2015-02-26 15:47:56 +00:00
}
};
}).call(this);