2016-01-04 03:58:51 +00:00
|
|
|
###
|
2017-06-14 21:20:15 +00:00
|
|
|
Copyright 2016-2017 Resin.io
|
2016-01-04 03:58:51 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
###
|
|
|
|
|
2018-02-01 15:48:01 +00:00
|
|
|
{ normalizeUuidProp } = require('../utils/normalization')
|
|
|
|
|
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
|
|
|
Examples:
|
2015-03-03 14:14:16 +00:00
|
|
|
|
2016-01-21 14:23:40 +00:00
|
|
|
$ resin logs 23c73a1
|
|
|
|
$ resin logs 23c73a1
|
2015-08-13 18:33:19 +00:00
|
|
|
'''
|
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'
|
2015-10-01 14:39:36 +00:00
|
|
|
primary: true
|
2015-01-16 12:34:59 +00:00
|
|
|
action: (params, options, done) ->
|
2018-02-01 15:48:01 +00:00
|
|
|
normalizeUuidProp(params)
|
2018-06-29 18:08:10 +00:00
|
|
|
resin = require('resin-sdk').fromSharedOptions()
|
2015-12-12 00:28:29 +00:00
|
|
|
moment = require('moment')
|
2015-12-07 14:32:24 +00:00
|
|
|
|
2015-12-12 00:28:29 +00:00
|
|
|
printLine = (line) ->
|
|
|
|
timestamp = moment(line.timestamp).format('DD.MM.YY HH:mm:ss (ZZ)')
|
|
|
|
console.log("#{timestamp} #{line.message}")
|
|
|
|
|
2018-07-12 13:23:33 +00:00
|
|
|
promise = if options.tail
|
|
|
|
resin.logs.subscribe(params.uuid).then (logs) ->
|
|
|
|
logs.on('line', printLine)
|
|
|
|
logs.on('error', done)
|
|
|
|
else
|
|
|
|
resin.logs.history(params.uuid).each(printLine)
|
|
|
|
|
|
|
|
promise.catch(done)
|