Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 9f16a71a14ae51cfb8da1e98cf7f35f7e07948a5 1 parent 8a46952
Mike D Pilsbury pekim authored
9 src/debug.coffee
... ... @@ -1,6 +1,8 @@
1 1 EventEmitter = require('events').EventEmitter
2 2 util = require('util')
3 3
  4 +packetHeaderToString = require('./packet').headerToString
  5 +
4 6 class Debug extends EventEmitter
5 7 ###
6 8 @options Which debug details should be sent.
@@ -16,15 +18,16 @@ class Debug extends EventEmitter
16 18
17 19 @indent = ' '
18 20
19   - packet: (direction, packet) ->
  21 + packetHeader: (direction, header) ->
20 22 if @haveListeners() && @options.packet
21 23 @log('')
22 24 @log(direction)
23   - @log(packet.headerToString(@indent))
  25 + @log(packetHeaderToString(header, @indent))
24 26
25 27 data: (packet) ->
26 28 if @haveListeners() && @options.data
27   - @log(packet.dataToString(@indent))
  29 + console.log packet
  30 + #@log(packet.dataToString(@indent))
28 31
29 32 payload: (generatePayloadText) ->
30 33 if @haveListeners() && @options.payload
12 src/message-io.coffee
@@ -25,7 +25,7 @@ class MessageIO extends EventEmitter
25 25 break
26 26 @advanceReceived(packetHeaderLength)
27 27
28   - @processReceivedPacket(header.payloadLength)
  28 + @processReceivedPacket(header, header.payloadLength)
29 29
30 30 if header.endOfMessage
31 31 @emit('message')
@@ -46,7 +46,8 @@ class MessageIO extends EventEmitter
46 46 @receivedBuffers[0] = @receivedBuffers[0].slice(length)
47 47 length = 0
48 48
49   - processReceivedPacket: (length) ->
  49 + processReceivedPacket: (header, length) ->
  50 + @debug.packetHeader('Received', header)
50 51 @receivedAvailable -= length
51 52
52 53 while length
@@ -92,11 +93,12 @@ class MessageIO extends EventEmitter
92 93 @sendPacket(header, packetPayload)
93 94
94 95 sendPacket: (header, payload) =>
95   - #@logPacket('Sent', packet);
  96 + @logPacket('Sent', header, payload);
96 97 @socket.write(header.concat(payload))
97 98
98   - logPacket: (direction, packet) ->
99   - @debug.packet(direction, packet)
  99 + logPacket: (direction, header, packet) ->
  100 + header = decodePacketHeader(header)
  101 + @debug.packetHeader(direction, header)
100 102 @debug.data(packet)
101 103
102 104 module.exports = MessageIO
2  test/unit/debug-test.coffee
@@ -9,6 +9,7 @@ class Packet
9 9 dataToString: ->
10 10 'data'
11 11
  12 +###
12 13 exports.packet = (test) ->
13 14 emitCount = 0;
14 15
@@ -88,3 +89,4 @@ exports.payloadNotEnabled = (test) ->
88 89 debug.token({name: 'test'})
89 90
90 91 test.done()
  92 +###

0 comments on commit 9f16a71

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