summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon.py6
-rw-r--r--server/handlers.py15
-rw-r--r--server/problems.py3
-rw-r--r--server/socket.py8
-rw-r--r--web/main.js2
5 files changed, 18 insertions, 16 deletions
diff --git a/daemon.py b/daemon.py
index 8a03d4c..8a7c971 100644
--- a/daemon.py
+++ b/daemon.py
@@ -2,8 +2,8 @@
# coding=utf-8
if __name__ == '__main__':
- # import server
- # server.start()
+ import os
+ import logging
+ logging.basicConfig(filename=os.environ.get('CODEQ_SERVER_LOG') or 'codeq-server.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
import server
-# import server.socket
server.socket.serve_forever()
diff --git a/server/handlers.py b/server/handlers.py
index 99b021f..0a77e66 100644
--- a/server/handlers.py
+++ b/server/handlers.py
@@ -4,6 +4,7 @@ from concurrent.futures import ThreadPoolExecutor
import traceback
from errors.session import *
import server
+import logging
class CodeqService(object):
@@ -311,15 +312,15 @@ _executor = ThreadPoolExecutor(max_workers=100)
def _invoke_handler(handler, request):
try:
- print('Worker thread processing data={}'.format(str(request.data)))
+ logging.debug('Worker thread processing data={}'.format(str(request.data)))
handler.process(request)
if not request.is_finished:
- print('ERROR: the request was not concluded!')
+ logging.error('ERROR: the request was not concluded!')
request.reply({'code': -1, 'message': 'Request processing did not provide a reply'})
- print('Processing finished')
+ logging.debug('Processing finished')
except Exception as e:
- print('ERROR: data processing failed: ' + str(e))
- traceback.print_exc()
+ logging.critical('ERROR: data processing failed: ' + str(e))
+ logging.critical(traceback.format_exc())
request.reply({'code': -1, 'message': 'Internal error: ' + str(e)})
def serve_request(json_obj):
@@ -335,7 +336,7 @@ def serve_request(json_obj):
handler = incoming_handlers.get(action)
if handler is None:
raise RequestProcessingError('No handler for ' + action)
- print("Attempting to serve action={}".format(action))
+ logging.debug("Attempting to serve action={}".format(action))
session = None
if sid is None:
if not handler.session_is_optional:
@@ -351,7 +352,7 @@ def serve_request(json_obj):
def send(tid, sid, json_obj):
# just a proxy function for now
- print('Sending reply: {}'.format(str(json_obj)))
+ logging.debug('Sending reply: {}'.format(str(json_obj)))
server.socket.sendPacket(tid, sid, json_obj)
def stop():
diff --git a/server/problems.py b/server/problems.py
index 220a746..bc124ca 100644
--- a/server/problems.py
+++ b/server/problems.py
@@ -5,6 +5,7 @@ import importlib.machinery
import threading
import os.path
from db import get_connection, return_connection
+import logging
_path_prefix = os.environ.get('CODEQ_PROBLEMS') or '/var/local/codeq-problems'
_module_loading_lock = threading.RLock() # TODO: make a more fine-grained locking import machinery
@@ -19,7 +20,7 @@ def load_module(fullname):
ff = importlib.machinery.FileFinder(d, (importlib.machinery.SourceFileLoader, ['.py']))
spec = ff.find_spec(fullname)
if spec is None:
- print('ERROR: there is no problem module {0}'.format(fullname))
+ logging.error('ERROR: there is no problem module {0}'.format(fullname))
return None
mod = type(sys)(fullname)
mod.__loader__ = spec.loader
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:
diff --git a/web/main.js b/web/main.js
index 16b318d..2446010 100644
--- a/web/main.js
+++ b/web/main.js
@@ -5,7 +5,7 @@ var engine = require('engine.io'),
log4js = require('log4js');
log4js.loadAppender('file');
-log4js.addAppender(log4js.appenders.file('web.log'), 'log');
+log4js.addAppender(log4js.appenders.file(process.env.CODEQ_WEB_LOG || 'codeq-web.log'), 'log');
var logger = log4js.getLogger('log');
var logException = function (msg, error) {