Add session encoding debug logging to the server

This change adds debug logging statements for the request and
response message encodings sent and received by the server
session. These provide direct visability into each message that
is handled by the server, facilitating debugging and correctness
checking. Given the content of these encodings may contain
sensitive information, debug logging should only be enabled when
testing or developing server features.
This commit is contained in:
Peter Hamilton 2019-07-19 10:57:43 -04:00 committed by Peter Hamilton
parent 6dcae13c5b
commit 8441bb4302
1 changed files with 7 additions and 0 deletions

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import binascii
import logging
import socket
import struct
@ -345,8 +346,14 @@ class KmipSession(threading.Thread):
"does not match the advertised header length."
)
else:
self._logger.debug(
"Request encoding: {}".format(binascii.hexlify(message))
)
return message
def _send_response(self, data):
if len(data) > 0:
self._logger.debug(
"Response encoding: {}".format(binascii.hexlify(bytes(data)))
)
self._connection.sendall(bytes(data))