完善日志记录

This commit is contained in:
virusdefender 2016-10-04 13:24:50 +08:00
parent 28851ee4ca
commit e362434700
3 changed files with 18 additions and 19 deletions

View File

@ -5,7 +5,6 @@ import hashlib
import json
import os
import shutil
import logging
import web
@ -13,7 +12,7 @@ from compiler import Compiler
from config import JUDGER_WORKSPACE_BASE, TEST_CASE_DIR
from exception import TokenVerificationFailed, CompileError, SPJCompileError,JudgeClientError
from judge_client import JudgeClient
from utils import server_info, get_token
from utils import server_info, get_token, logger
DEBUG = os.environ.get("judger_debug") == "1"
@ -28,7 +27,7 @@ class InitSubmissionEnv(object):
os.mkdir(self.path)
os.chmod(self.path, 0777)
except Exception as e:
logging.exception(e)
logger.exception(e)
raise JudgeClientError("failed to create runtime dir")
return self.path
@ -37,7 +36,7 @@ class InitSubmissionEnv(object):
try:
shutil.rmtree(self.path)
except Exception as e:
logging.exception(e)
logger.exception(e)
raise JudgeClientError("failed to clean runtime dir")
@ -110,7 +109,7 @@ class JudgeServer(object):
try:
data = json.loads(web.data())
except Exception as e:
logging.info(web.data())
logger.info(web.data())
return {"ret": "ServerError", "data": "invalid json"}
else:
data = {}
@ -125,13 +124,13 @@ class JudgeServer(object):
return json.dumps({"err": "InvalidMethod", "data": None})
return json.dumps({"err": None, "data": callback(**data)})
except (CompileError, TokenVerificationFailed, SPJCompileError, JudgeClientError) as e:
logging.exception(e)
logger.exception(e)
ret = dict()
ret["err"] = e.__class__.__name__
ret["data"] = e.message
return json.dumps(ret)
except Exception as e:
logging.exception(e)
logger.exception(e)
ret = dict()
ret["err"] = "JudgeClientError"
ret["data"] =e.__class__.__name__ + ":" + e.message
@ -146,7 +145,7 @@ urls = (
if DEBUG:
logging.info("DEBUG=ON")
logger.info("DEBUG=ON")
# check token
JudgeServer()._token

View File

@ -2,19 +2,10 @@
from __future__ import unicode_literals
import os
import json
import logging
import requests
from exception import JudgeServiceError
from utils import server_info, get_token
logger = logging.getLogger(__name__)
handler = logging.FileHandler("/log/service_log.log")
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.WARNING)
from utils import server_info, get_token, logger
class JudgeService(object):

View File

@ -4,6 +4,7 @@ import _judger
import psutil
import socket
import os
import logging
def server_info():
@ -16,4 +17,12 @@ def server_info():
def get_token():
return os.environ.get("OJ_WEB_SERVER_ENV_judger_token") or os.environ.get("judger_token")
return os.environ.get("OJ_WEB_SERVER_ENV_judger_token") or os.environ.get("judger_token")
logger = logging.getLogger(__name__)
handler = logging.FileHandler("/log/judge_server.log")
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.WARNING)