From e890c0e188ee8cf03bdf887d40289bd236207251 Mon Sep 17 00:00:00 2001 From: Jesse Cirimelli-Low Date: Wed, 13 Feb 2019 15:21:16 -0800 Subject: [PATCH] fixed -v logging --- compiler/debug.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/compiler/debug.py b/compiler/debug.py index e6c6a1bd..f25ff4b5 100644 --- a/compiler/debug.py +++ b/compiler/debug.py @@ -16,7 +16,7 @@ def check(check, str): index) = inspect.getouterframes(inspect.currentframe())[1] sys.stderr.write("ERROR: file {0}: line {1}: {2}\n".format( os.path.basename(filename), line_number, str)) - log("ERROR: file {0}: line {1}: {2}\n".format( + logger.log("ERROR: file {0}: line {1}: {2}\n".format( os.path.basename(filename), line_number, str)) assert 0 @@ -27,7 +27,7 @@ def error(str, return_value=0): index) = inspect.getouterframes(inspect.currentframe())[1] sys.stderr.write("ERROR: file {0}: line {1}: {2}\n".format( os.path.basename(filename), line_number, str)) - log("ERROR: file {0}: line {1}: {2}\n".format( + logger.log("ERROR: file {0}: line {1}: {2}\n".format( os.path.basename(filename), line_number, str)) assert return_value == 0 @@ -38,7 +38,7 @@ def warning(str): index) = inspect.getouterframes(inspect.currentframe())[1] sys.stderr.write("WARNING: file {0}: line {1}: {2}\n".format( os.path.basename(filename), line_number, str)) - log("WARNING: file {0}: line {1}: {2}\n".format( + logger.log("WARNING: file {0}: line {1}: {2}\n".format( os.path.basename(filename), line_number, str)) @@ -48,17 +48,27 @@ def print_raw(str): def log(str): - if log.create_file: - compile_log = open(globals.OPTS.output_path + - globals.OPTS.output_name + '.log', "w") - log.create_file = 0 + if globals.OPTS.output_name != '': + if log.create_file: + compile_log = open(globals.OPTS.output_path + + globals.OPTS.output_name + '.log', "w+") + log.create_file = 0 + else: + compile_log = open(globals.OPTS.output_path + + globals.OPTS.output_name + '.log', "a") + + if len(log.setup_output) != 0: + for line in log.setup_output: + compile_log.write(line) + log.setup_output = [] + compile_log.write(str + '\n') else: - compile_log = open(globals.OPTS.output_path + - globals.OPTS.output_name + '.log', "a") - compile_log.write(str + '\n') -log.create_file = 1 + log.setup_output.append(str + "\n") +# use a static list of strings to store messages until the global paths are set up +log.setup_output = [] +log.create_file = 1 def info(lev, str): @@ -71,5 +81,5 @@ def info(lev, str): class_name = "" else: class_name = mod.__name__ - print_raw("[{0}/{1}]: {2}".format(class_name, frm[0].f_code.co_name, str)) - + print_raw("[{0}/{1}]: {2}".format(class_name, + frm[0].f_code.co_name, str))