Skip to content
Browse files

Make debug logging of unfinished async processing a little less messy.

  • Loading branch information...
1 parent 8a46952 commit 9f16a71a14ae51cfb8da1e98cf7f35f7e07948a5 @pekim pekim committed Jul 1, 2012
Showing with 15 additions and 8 deletions.
  1. +6 −3 src/debug.coffee
  2. +7 −5 src/message-io.coffee
  3. +2 −0 test/unit/debug-test.coffee
View
9 src/debug.coffee
@@ -1,6 +1,8 @@
EventEmitter = require('events').EventEmitter
util = require('util')
+packetHeaderToString = require('./packet').headerToString
+
class Debug extends EventEmitter
###
@options Which debug details should be sent.
@@ -16,15 +18,16 @@ class Debug extends EventEmitter
@indent = ' '
- packet: (direction, packet) ->
+ packetHeader: (direction, header) ->
if @haveListeners() && @options.packet
@log('')
@log(direction)
- @log(packet.headerToString(@indent))
+ @log(packetHeaderToString(header, @indent))
data: (packet) ->
if @haveListeners() && @options.data
- @log(packet.dataToString(@indent))
+ console.log packet
+ #@log(packet.dataToString(@indent))
payload: (generatePayloadText) ->
if @haveListeners() && @options.payload
View
12 src/message-io.coffee
@@ -25,7 +25,7 @@ class MessageIO extends EventEmitter
break
@advanceReceived(packetHeaderLength)
- @processReceivedPacket(header.payloadLength)
+ @processReceivedPacket(header, header.payloadLength)
if header.endOfMessage
@emit('message')
@@ -46,7 +46,8 @@ class MessageIO extends EventEmitter
@receivedBuffers[0] = @receivedBuffers[0].slice(length)
length = 0
- processReceivedPacket: (length) ->
+ processReceivedPacket: (header, length) ->
+ @debug.packetHeader('Received', header)
@receivedAvailable -= length
while length
@@ -92,11 +93,12 @@ class MessageIO extends EventEmitter
@sendPacket(header, packetPayload)
sendPacket: (header, payload) =>
- #@logPacket('Sent', packet);
+ @logPacket('Sent', header, payload);
@socket.write(header.concat(payload))
- logPacket: (direction, packet) ->
- @debug.packet(direction, packet)
+ logPacket: (direction, header, packet) ->
+ header = decodePacketHeader(header)
+ @debug.packetHeader(direction, header)
@debug.data(packet)
module.exports = MessageIO
View
2 test/unit/debug-test.coffee
@@ -9,6 +9,7 @@ class Packet
dataToString: ->
'data'
+###
exports.packet = (test) ->
emitCount = 0;
@@ -88,3 +89,4 @@ exports.payloadNotEnabled = (test) ->
debug.token({name: 'test'})
test.done()
+###

0 comments on commit 9f16a71

Please sign in to comment.
Something went wrong with that request. Please try again.