From 63a852da581bd58975f021ef1adda07312183881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Mon, 5 Oct 2015 17:50:23 +0200 Subject: Add logging to file to python server. Configure logfile paths from environment variables CODEQ_SERVER_LOG and CODEQ_WEB_LOG. --- server/socket.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/socket.py') diff --git a/server/socket.py b/server/socket.py index 121c6a4..bdf99bf 100644 --- a/server/socket.py +++ b/server/socket.py @@ -6,9 +6,9 @@ import json import threading import traceback from server.handlers import serve_request +import logging # TODO: add a whole lot of try..except blocks, and just make it overall error resistant -# TODO: add logging _mapping_lock = threading.Lock() # the lock guarding access to the two mappings below @@ -18,7 +18,7 @@ _transactions_to_socket = {} # keyed by tid, used only when there is no sid ava def processIncomingPacket(receiving_socket, packet): - print('Decoding JSON: {}'.format(packet)) + logging.debug('Decoding JSON: {}'.format(packet)) obj = json.loads(packet) req_type = obj.get('type') # private (meta) requests have the 'type' if req_type == 'connect': @@ -125,7 +125,7 @@ class JsonClientSocket(SocketHandler): self.destroy() else: # packet decode loop - print("received: {}".format(data)) + logging.debug("received: {}".format(data)) offset = 0 N = len(data) while (offset < N): @@ -160,7 +160,7 @@ class JsonClientSocket(SocketHandler): processIncomingPacket(self, s.decode('utf-8')) except Exception as e: # any exception that propagates to here means a possible protocol error, we have to disconnect - traceback.print_exc() + logging.critical(traceback.format_exc()) self.destroy() return else: -- cgit v1.2.1