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