mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +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 syrup = require('syrup')
|
||||||
|
|
||||||
var logger = require('../util/logger')
|
var logger = require('../util/logger')
|
||||||
|
var lifecycle = require('../util/lifecycle')
|
||||||
|
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
// Show serial number in logs
|
// Show serial number in logs
|
||||||
logger.setGlobalIdentifier(options.serial)
|
logger.setGlobalIdentifier(options.serial)
|
||||||
|
|
||||||
|
var log = logger.createLogger('device')
|
||||||
|
|
||||||
return syrup.serial()
|
return syrup.serial()
|
||||||
// We want to send logs before anything else start happening
|
// We want to send logs before anything else start happening
|
||||||
.dependency(require('./device/plugins/logsender'))
|
.dependency(require('./device/plugins/logsender'))
|
||||||
|
@ -35,4 +38,8 @@ module.exports = function(options) {
|
||||||
.consume(options)
|
.consume(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 syrup = require('syrup')
|
||||||
var request = Promise.promisifyAll(require('request'))
|
var request = Promise.promisifyAll(require('request'))
|
||||||
var httpProxy = require('http-proxy')
|
var httpProxy = require('http-proxy')
|
||||||
var split = require('split')
|
|
||||||
|
|
||||||
var logger = require('../../../util/logger')
|
var logger = require('../../../util/logger')
|
||||||
var devutil = require('../../../util/devutil')
|
var devutil = require('../../../util/devutil')
|
||||||
var lifecycle = require('../../../util/lifecycle')
|
var lifecycle = require('../../../util/lifecycle')
|
||||||
|
var streamutil = require('../../../util/streamutil')
|
||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('../support/adb'))
|
.dependency(require('../support/adb'))
|
||||||
|
@ -35,10 +35,7 @@ module.exports = syrup.serial()
|
||||||
])
|
])
|
||||||
.then(function(out) {
|
.then(function(out) {
|
||||||
lifecycle.share('Remote shell', out)
|
lifecycle.share('Remote shell', out)
|
||||||
out.pipe(split())
|
streamutil.talk(log, 'Remote shell says: "%s"', out)
|
||||||
.on('data', function(chunk) {
|
|
||||||
log.info('Remote says: "%s"', chunk)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return devutil.waitForPort(adb, options.serial, service.port)
|
return devutil.waitForPort(adb, options.serial, service.port)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
var util = require('util')
|
var util = require('util')
|
||||||
|
|
||||||
var syrup = require('syrup')
|
var syrup = require('syrup')
|
||||||
var split = require('split')
|
|
||||||
var Promise = require('bluebird')
|
var Promise = require('bluebird')
|
||||||
|
|
||||||
var wire = require('../../../wire')
|
var wire = require('../../../wire')
|
||||||
|
@ -50,10 +49,7 @@ module.exports = syrup.serial()
|
||||||
})
|
})
|
||||||
.then(function(out) {
|
.then(function(out) {
|
||||||
lifecycle.share('InputAgent shell', out)
|
lifecycle.share('InputAgent shell', out)
|
||||||
out.pipe(split())
|
streamutil.talk(log, 'InputAgent says: "%s"', out)
|
||||||
.on('data', function(chunk) {
|
|
||||||
log.info('Agent says: "%s"', chunk)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return devutil.waitForPort(adb, options.serial, agent.port)
|
return devutil.waitForPort(adb, options.serial, agent.port)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
var syrup = require('syrup')
|
var syrup = require('syrup')
|
||||||
var split = require('split')
|
|
||||||
|
|
||||||
var logger = require('../../../util/logger')
|
var logger = require('../../../util/logger')
|
||||||
var devutil = require('../../../util/devutil')
|
var devutil = require('../../../util/devutil')
|
||||||
var lifecycle = require('../../../util/lifecycle')
|
var lifecycle = require('../../../util/lifecycle')
|
||||||
|
var streamutil = require('../../../util/streamutil')
|
||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('../support/adb'))
|
.dependency(require('../support/adb'))
|
||||||
|
@ -24,11 +24,8 @@ module.exports = syrup.serial()
|
||||||
, '--listen-stats', service.port
|
, '--listen-stats', service.port
|
||||||
])
|
])
|
||||||
.then(function(out) {
|
.then(function(out) {
|
||||||
lifecycle.share('Stats remote shell', out)
|
lifecycle.share('Stats shell', out)
|
||||||
out.pipe(split())
|
streamutil.talk(log, 'Stats shell says: "%s"', out)
|
||||||
.on('data', function(chunk) {
|
|
||||||
log.info('Remote says: "%s"', chunk)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
var Promise = require('bluebird')
|
var Promise = require('bluebird')
|
||||||
var syrup = require('syrup')
|
var syrup = require('syrup')
|
||||||
var split = require('split')
|
|
||||||
var monkey = require('adbkit-monkey')
|
var monkey = require('adbkit-monkey')
|
||||||
|
|
||||||
var wire = require('../../../wire')
|
var wire = require('../../../wire')
|
||||||
var devutil = require('../../../util/devutil')
|
var devutil = require('../../../util/devutil')
|
||||||
var logger = require('../../../util/logger')
|
var logger = require('../../../util/logger')
|
||||||
var lifecycle = require('../../../util/lifecycle')
|
var lifecycle = require('../../../util/lifecycle')
|
||||||
|
var streamutil = require('../../../util/streamutil')
|
||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('../support/adb'))
|
.dependency(require('../support/adb'))
|
||||||
|
@ -30,11 +30,8 @@ module.exports = syrup.serial()
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
.then(function(out) {
|
.then(function(out) {
|
||||||
lifecycle.share('Touch remote shell', out)
|
lifecycle.share('Touch shell', out)
|
||||||
out.pipe(split())
|
streamutil.talk(log, 'Touch shell says: "%s"', out)
|
||||||
.on('data', function(chunk) {
|
|
||||||
log.info('Remote says: "%s"', chunk)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return devutil.waitForPort(adb, options.serial, service.port)
|
return devutil.waitForPort(adb, options.serial, service.port)
|
||||||
|
|
|
@ -43,7 +43,6 @@ module.exports.readAll = function(stream) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports.findLine = function(stream, re) {
|
module.exports.findLine = function(stream, re) {
|
||||||
var resolver = Promise.defer()
|
var resolver = Promise.defer()
|
||||||
, piped = stream.pipe(split())
|
, piped = stream.pipe(split())
|
||||||
|
@ -73,3 +72,13 @@ module.exports.findLine = function(stream, re) {
|
||||||
stream.unpipe(piped)
|
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