Skip to content

Commit

Permalink
implement #39 - user config parallel python logging destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbarnett-rice committed Aug 1, 2017
1 parent 1ab4829 commit a1232e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/main/bash/binary_release/start_bayou.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ mkdir -p logs

java -DconfigurationFile=resources/conf/apiSynthesisServerConfig.properties -Dlog4j.configurationFile=resources/conf/apiSynthesisServerLog4j2.xml -jar bayou-1.0.0.jar &

if [ $# -eq 0 ]
then
logs_dir="logs"
else
logs_dir=$1
fi

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export PYTHONPATH=python
python3 python/ast_server.py --save_dir "$SCRIPT_DIR/resources/model"
python3 python/ast_server.py --save_dir "$SCRIPT_DIR/resources/model" --logs_dir $logs_dir
19 changes: 10 additions & 9 deletions src/main/python/ast_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ def okay(js, ast):
return ev_okay


def _generate_asts(evidence_json, predictor):
def _generate_asts(evidence_json, predictor, predictor_samples_count = 25):
logging.debug("entering")
js = json.loads(evidence_json) # parse evidence as a JSON string

#
# Generate ASTs from evidence.
#
asts, counts = [], []
for i in range(100):
for i in range(predictor_samples_count):
try:
ast = predictor.infer(js)
ast['calls'] = list(set(predictor.calls_in_last_ast))
Expand Down Expand Up @@ -151,20 +151,21 @@ def _generate_asts(evidence_json, predictor):
# Parse command line args.
parser = argparse.ArgumentParser()
parser.add_argument('--save_dir', type=str, required=True,help='model directory to laod from')
parser.add_argument('--logs_dir', type=str, required=False, help='the directory to store log information')
parser.add_argument('--logs_dir', type=str, required=False, help='the directories to store log information seperated by the OS path seperator')
args = parser.parse_args()

if args.logs_dir is None:
dirpath = os.path.dirname(__file__);
logpath = os.path.join(dirpath, "../logs/ast_server.log")
logpaths = [os.path.join(dirpath, "../logs/ast_server.log")]
else:
logpath = args.logs_dir + "/ast_server.log"
logpaths = [(dir + "/ast_server.log") for dir in args.logs_dir.split(os.pathsep)]

# Create the logger for the application.
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(threadName)s %(filename)s:%(lineno)d] %(message)s',
datefmt='%d-%m-%Y:%H:%M:%S',
level=logging.DEBUG,
handlers=[logging.handlers.RotatingFileHandler(logpath, maxBytes=100000000, backupCount=9)])
for logpath in logpaths:
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(threadName)s %(filename)s:%(lineno)d] %(message)s',
datefmt='%d-%m-%Y:%H:%M:%S',
level=logging.DEBUG,
handlers=[logging.handlers.RotatingFileHandler(logpath, maxBytes=100000000, backupCount=9) for logpath in logpaths])

# Start processing requests.
_start_server(args.save_dir)

0 comments on commit a1232e5

Please sign in to comment.