Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toggle the logging from command line #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion al_hostserver/altrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
# only safe to set when running locally. On a production server allowing
# this to remain true is major security hole.
AL_HOST_FETCH_ABOVE_ROOT = True
DEBUGGING_STATE = False

import sys
sys.path.append('../')

def find_conf(cwd):
split_path = os.path.normpath(cwd).split(os.sep)
Expand Down Expand Up @@ -284,6 +287,9 @@ def parse_args(argv):
help="Specifies the directory of the outer loop repo.")
parser.add_argument('--outer-loop-url', default=None, dest="outer_loop_url", metavar="<outer_loop_url>",
help="Specifies the URL of a running outer loop server.")
parser.add_argument('--debug', action='store_true', help="Makes logging messages visible in the console.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the behavior of this flag different form other debugging flags? It seems like this one corresponds to debugging in the host_server specifically. Can it be given a more descriptive name? Alternatively, see my other comment that it could maybe be part of a delimited list of loggers to activate.

parser.add_argument('--debug-agent', action='store_true', dest="debug_agent", help="Makes logging messages for the agent visible in the console.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its a good idea to constantly add new flags for different debuggers like this. There are many more instances of the logging module used throughout AL_Core that would not respond to this style of flagging. A more general solution where you provide some kind of delimited list that switches on multiple loggers at once seems like the ideal in this case.

parser.add_argument('--debug-performance', action='store_true', dest="debug_performance", help="Makes logging messages for performance visible in the console.")

try:
args = parser.parse_args(argv)
Expand Down Expand Up @@ -328,6 +334,7 @@ def parse_args(argv):
args.log_dir = os.path.abspath(apply_wd(args.log_dir))
args.al_dir = os.path.abspath(apply_wd(args.al_dir))
args.html_bridge_dir = dir_from_package("al_hostserver")
args.modular_agent_dir = os.path.abspath(apply_wd(args.al_dir))
# os.path.join(calling_dir,args.al_dir)

assert os.path.isfile(training_abs), "No such file %r" % training_abs
Expand Down Expand Up @@ -362,7 +369,7 @@ def parse_args(argv):


def main(args):
global al_process, ctat_process, browser_process, outer_loop_process, calling_dir
global al_process, ctat_process, browser_process, outer_loop_process, calling_dir, logging_process

if args.no_al_server:
assert args.al_port is not None, "Must specify AL_PORT in altrain.conf or command line"
Expand All @@ -382,6 +389,21 @@ def main(args):
if(check_port(args.ctat_host, args.ctat_port, args.force)):
_env = os.environ.copy()
_env["AL_HOST_FETCH_ABOVE_ROOT"] = str(AL_HOST_FETCH_ABOVE_ROOT)
DEBUGGING_STATE = False
if(args.debug or args.debug_agent or args.debug_performance):
_env["DEBUGGING_STATE"] = "True"
else:
_env["DEBUGGING_STATE"] = "False"
if(args.debug_agent):
_env["DEBUGGING_AGENT"] = "True"
else:
_env["DEBUGGING_AGENT"] = "False"
if(args.debug_performance):
_env["DEBUGGING_PERFORMANCE"] = "True"
else:
_env["DEBUGGING_PERFORMANCE"] = "False"
logging_process = subprocess.Popen([sys.executable, os.path.join(
args.al_dir, "agents", "ModularAgent.py")], env=_env)
ctat_process = subprocess.Popen([
sys.executable, os.path.join(
args.html_bridge_dir, "host_server.py"),
Expand Down
15 changes: 7 additions & 8 deletions al_hostserver/host_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from glob import glob
# from flask import Flask,

FETCH_ABOVE_ROOT = str(os.environ.get("AL_HOST_FETCH_ABOVE_ROOT","False")).lower() == "true"
FETCH_ABOVE_ROOT = str(os.environ.get("AL_HOST_FETCH_ABOVE_ROOT","False")).lower() == "true"
debuggingState = str(os.environ.get("DEBUGGING_STATE", "False")).lower() == "true"

print("FETCH_ABOVE_ROOT", FETCH_ABOVE_ROOT)

Expand Down Expand Up @@ -99,17 +100,15 @@ def check_started(host,port):


class HostServer(Flask):
def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
thread = threading.Thread(target=lambda : check_started(host,port))
thread.start()
super(HostServer, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)
def run(self, host=None, port=None, debug=debuggingState, load_dotenv=True, **options):
thread = threading.Thread(target=lambda : check_started(host,port))
thread.start()
super(HostServer, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)

print("HOST CWD", os.getcwd(), __name__)
# app = HostServer(__name__,static_folder='.',root_path=os.getcwd())
app = HostServer(__name__,static_folder=".")#,root_path=os.getcwd())



# output.write("Anon Student Id\tSession Id\tTime\tStudent Response Type\tTutor Response Type\tLevel (Unit)\tProblemName\tStep Name\tSelection\tAction\tInput\tFeedback Text\tOutcome\n");
LOG_HEADERS = {"user_guid" :"Anon Student Id",
"session_id" :"Session Id",
Expand Down Expand Up @@ -755,7 +754,7 @@ def handle_host(path):
log_file_handle = open(output_file_path, 'a', newline='')
csv_writer = csv.DictWriter(log_file_handle, LOG_HEADERS.values(),delimiter="\t")
log = logging.getLogger('werkzeug')
log.disabled = True
log.disabled

app.run(HOST_DOMAIN,port,threaded=True)
# print("IT DIED")