From ccef3624df81ac8710611ce15e4b5bde08766065 Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Mon, 17 Mar 2014 16:41:07 +0900 Subject: [PATCH] Send device logs to app. --- lib/roles/app.js | 3 +++ lib/roles/device.js | 3 ++- lib/roles/device/plugins/logsender.js | 11 +++++++++-- lib/roles/notify/hipchat.js | 2 +- lib/wire/util.js | 1 - 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/roles/app.js b/lib/roles/app.js index 4f5a2aef..a135adb6 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -245,6 +245,9 @@ module.exports = function(options) { } var messageListener = wirerouter() + .on(wire.DeviceLogMessage, function(channel, message) { + socket.emit('device.log', message) + }) .on(wire.DevicePresentMessage, function(channel, message) { socket.emit('device.add', { serial: message.serial diff --git a/lib/roles/device.js b/lib/roles/device.js index 70655d76..cc370c58 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -10,6 +10,8 @@ module.exports = function(options) { // We want to send logs before anything else start happening .dependency(require('./device/plugins/logsender')) .define(function(options) { + var log = logger.createLogger('device') + log.info('Preparing device') return syrup() .dependency(require('./device/plugins/solo')) .dependency(require('./device/plugins/heartbeat')) @@ -21,7 +23,6 @@ module.exports = function(options) { .dependency(require('./device/plugins/touch')) .dependency(require('./device/plugins/owner')) .define(function(options, solo) { - var log = logger.createLogger('device') if (process.send) { // Only if we have a parent process process.send('ready') diff --git a/lib/roles/device/plugins/logsender.js b/lib/roles/device/plugins/logsender.js index c7228f2d..1633a44c 100644 --- a/lib/roles/device/plugins/logsender.js +++ b/lib/roles/device/plugins/logsender.js @@ -1,3 +1,4 @@ +var Promise = require('bluebird') var syrup = require('syrup') var logger = require('../../../util/logger') @@ -6,11 +7,12 @@ var wireutil = require('../../../wire/util') module.exports = syrup() .dependency(require('../support/push')) - .define(function(options, push) { + .dependency(require('../support/quit')) + .define(function(options, push, quit) { // Forward all logs logger.on('entry', function(entry) { push.send([ - wireutil.log + wireutil.global , wireutil.envelope(new wire.DeviceLogMessage( options.serial , entry.timestamp / 1000 @@ -23,5 +25,10 @@ module.exports = syrup() ]) }) + quit.observe(function() { + // Let's give it some time to flush logs before dying + return Promise.delay(500) + }) + return logger }) diff --git a/lib/roles/notify/hipchat.js b/lib/roles/notify/hipchat.js index 354739e7..5556fa5c 100644 --- a/lib/roles/notify/hipchat.js +++ b/lib/roles/notify/hipchat.js @@ -23,7 +23,7 @@ module.exports = function(options) { }) // Establish always-on channels - ;[wireutil.log].forEach(function(channel) { + ;[wireutil.global].forEach(function(channel) { log.info('Subscribing to permanent channel "%s"', channel) sub.subscribe(channel) }) diff --git a/lib/wire/util.js b/lib/wire/util.js index 989b5fa5..1fa6f4d7 100644 --- a/lib/wire/util.js +++ b/lib/wire/util.js @@ -4,7 +4,6 @@ var wire = require('./') var wireutil = { global: '*ALL' -, log: '*LOG' , heartbeat: '*HB' , makePrivateChannel: function() { return uuid.v4(null, new Buffer(16)).toString('base64')