Logging at wire-protocol level?
Is there a simple way to enable logging at the wire-protocol level?
I've worked out how to DIY it via changes to node_modules/pg/lib/connection.js and node_modules/pg-protocol/dist/buffer-reader.js, but maybe there's a more formal approach? I also can't see any relevant log calls in those files.
Is the message event on Connections low-level enough for your needs?
Is the
messageevent onConnections low-level enough for your needs?
This looks really helpful, although maybe not as low-level as I may need for some purposes.
What's the correct way to enable this logging? I tried adding a 'message' event listener to my Pool instance, but no luck.
Instead I had a look at the messages like this:
--- lib/connection.js
+++ lib/connection.js
@@ -107,6 +107,7 @@
this.emit('end')
})
parse(stream, (msg) => {
+ console.log('emitting message:', msg);
var eventName = msg.name === 'error' ? 'errorMessage' : msg.name
if (this._emitMessage) {
this.emit('message', msg)
From the emitted msg object, how do you tell which direction each message is going?
The message event is only for incoming messages. You would add the event listener to each Connection object:
pool.on('connect', client => {
client.connection.on('message', …);
});