mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Refactor stream log output to a utility.
This commit is contained in:
parent
d6604bcda8
commit
e43507b686
6 changed files with 26 additions and 23 deletions
|
@ -1,11 +1,14 @@
|
|||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../util/logger')
|
||||
var lifecycle = require('../util/lifecycle')
|
||||
|
||||
module.exports = function(options) {
|
||||
// Show serial number in logs
|
||||
logger.setGlobalIdentifier(options.serial)
|
||||
|
||||
var log = logger.createLogger('device')
|
||||
|
||||
return syrup.serial()
|
||||
// We want to send logs before anything else start happening
|
||||
.dependency(require('./device/plugins/logsender'))
|
||||
|
@ -35,4 +38,8 @@ module.exports = function(options) {
|
|||
.consume(options)
|
||||
})
|
||||
.consume(options)
|
||||
.catch(function(err) {
|
||||
log.fatal('Setup had an error', err.stack)
|
||||
lifecycle.fatal()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ var Promise = require('bluebird')
|
|||
var syrup = require('syrup')
|
||||
var request = Promise.promisifyAll(require('request'))
|
||||
var httpProxy = require('http-proxy')
|
||||
var split = require('split')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var devutil = require('../../../util/devutil')
|
||||
var lifecycle = require('../../../util/lifecycle')
|
||||
var streamutil = require('../../../util/streamutil')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/adb'))
|
||||
|
@ -35,10 +35,7 @@ module.exports = syrup.serial()
|
|||
])
|
||||
.then(function(out) {
|
||||
lifecycle.share('Remote shell', out)
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
log.info('Remote says: "%s"', chunk)
|
||||
})
|
||||
streamutil.talk(log, 'Remote shell says: "%s"', out)
|
||||
})
|
||||
.then(function() {
|
||||
return devutil.waitForPort(adb, options.serial, service.port)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
var util = require('util')
|
||||
|
||||
var syrup = require('syrup')
|
||||
var split = require('split')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
var wire = require('../../../wire')
|
||||
|
@ -50,10 +49,7 @@ module.exports = syrup.serial()
|
|||
})
|
||||
.then(function(out) {
|
||||
lifecycle.share('InputAgent shell', out)
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
log.info('Agent says: "%s"', chunk)
|
||||
})
|
||||
streamutil.talk(log, 'InputAgent says: "%s"', out)
|
||||
})
|
||||
.then(function() {
|
||||
return devutil.waitForPort(adb, options.serial, agent.port)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var syrup = require('syrup')
|
||||
var split = require('split')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
var devutil = require('../../../util/devutil')
|
||||
var lifecycle = require('../../../util/lifecycle')
|
||||
var streamutil = require('../../../util/streamutil')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/adb'))
|
||||
|
@ -24,11 +24,8 @@ module.exports = syrup.serial()
|
|||
, '--listen-stats', service.port
|
||||
])
|
||||
.then(function(out) {
|
||||
lifecycle.share('Stats remote shell', out)
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
log.info('Remote says: "%s"', chunk)
|
||||
})
|
||||
lifecycle.share('Stats shell', out)
|
||||
streamutil.talk(log, 'Stats shell says: "%s"', out)
|
||||
})
|
||||
})
|
||||
.then(function() {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
var Promise = require('bluebird')
|
||||
var syrup = require('syrup')
|
||||
var split = require('split')
|
||||
var monkey = require('adbkit-monkey')
|
||||
|
||||
var wire = require('../../../wire')
|
||||
var devutil = require('../../../util/devutil')
|
||||
var logger = require('../../../util/logger')
|
||||
var lifecycle = require('../../../util/lifecycle')
|
||||
var streamutil = require('../../../util/streamutil')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/adb'))
|
||||
|
@ -30,11 +30,8 @@ module.exports = syrup.serial()
|
|||
])
|
||||
})
|
||||
.then(function(out) {
|
||||
lifecycle.share('Touch remote shell', out)
|
||||
out.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
log.info('Remote says: "%s"', chunk)
|
||||
})
|
||||
lifecycle.share('Touch shell', out)
|
||||
streamutil.talk(log, 'Touch shell says: "%s"', out)
|
||||
})
|
||||
.then(function() {
|
||||
return devutil.waitForPort(adb, options.serial, service.port)
|
||||
|
|
|
@ -43,7 +43,6 @@ module.exports.readAll = function(stream) {
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
module.exports.findLine = function(stream, re) {
|
||||
var resolver = Promise.defer()
|
||||
, piped = stream.pipe(split())
|
||||
|
@ -73,3 +72,13 @@ module.exports.findLine = function(stream, re) {
|
|||
stream.unpipe(piped)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.talk = function(log, format, stream) {
|
||||
stream.pipe(split())
|
||||
.on('data', function(chunk) {
|
||||
var line = chunk.toString().trim()
|
||||
if (line.length) {
|
||||
log.info(format, line)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue