2015-01-15 14:36:43 +00:00
|
|
|
_ = require('lodash')
|
2015-01-08 12:04:37 +00:00
|
|
|
resin = require('resin-sdk')
|
2014-11-28 16:46:24 +00:00
|
|
|
|
2015-05-18 13:37:27 +00:00
|
|
|
module.exports =
|
2015-01-15 17:10:14 +00:00
|
|
|
signature: 'logs <uuid>'
|
|
|
|
description: 'show device logs'
|
|
|
|
help: '''
|
2015-08-13 18:33:19 +00:00
|
|
|
Use this command to show logs for a specific device.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 18:33:19 +00:00
|
|
|
By default, the command prints all log messages and exit.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 18:33:19 +00:00
|
|
|
To continuously stream output, and see new logs in real time, use the `--tail` option.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 18:33:19 +00:00
|
|
|
Note that for now you need to provide the whole UUID for this command to work correctly.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 18:33:19 +00:00
|
|
|
This is due to some technical limitations that we plan to address soon.
|
2015-01-15 17:10:14 +00:00
|
|
|
|
2015-08-13 18:33:19 +00:00
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2015-08-13 18:33:19 +00:00
|
|
|
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828
|
|
|
|
$ resin logs 23c73a12e3527df55c60b9ce647640c1b7da1b32d71e6a39849ac0f00db828 --tail
|
|
|
|
'''
|
2015-01-15 17:10:14 +00:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
signature: 'tail'
|
|
|
|
description: 'continuously stream output'
|
|
|
|
boolean: true
|
|
|
|
alias: 't'
|
|
|
|
}
|
|
|
|
]
|
2015-01-16 12:34:59 +00:00
|
|
|
permission: 'user'
|
|
|
|
action: (params, options, done) ->
|
2015-07-22 22:06:53 +00:00
|
|
|
promise = resin.logs.history(params.uuid).each (line) ->
|
|
|
|
console.log(line.message)
|
|
|
|
|
|
|
|
if not options.tail
|
2015-08-13 19:08:16 +00:00
|
|
|
|
|
|
|
# PubNub keeps the process alive after a history query.
|
|
|
|
# Until this is fixed, we force the process to exit.
|
|
|
|
# This of course prevents this command to be used programatically
|
|
|
|
return promise.catch(done).finally ->
|
|
|
|
process.exit(0)
|
2015-07-22 22:06:53 +00:00
|
|
|
|
|
|
|
promise.then ->
|
|
|
|
resin.logs.subscribe(params.uuid).then (logs) ->
|
|
|
|
logs.on 'line', (line) ->
|
2015-04-27 13:30:57 +00:00
|
|
|
console.log(line.message)
|
2015-07-22 22:06:53 +00:00
|
|
|
logs.on('error', done)
|
|
|
|
.catch(done)
|