diff --git a/.gitignore b/.gitignore index 6c25327..b3e3458 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,4 @@ target/ *.idea #Subdivision Log Generator log file -logs/ +logs/* diff --git a/cli_application.py b/cli_application.py index 665bcf2..4d16962 100644 --- a/cli_application.py +++ b/cli_application.py @@ -4,16 +4,17 @@ """ import argparse import cmd -import logging.config import os import sys + from user_interface.curve_parser import parse_curve_file +from logger import get_logger class CliApplication(cmd.Cmd): def __init__(self, application_path=None, application_name="generator", args=None): - self.logger = logging.getLogger(__name__) + self.logger = get_logger(__name__) self.curve_paths = os.path.join(application_path, "test_curves") self.arguments = args self.parse_cmd_args(self.arguments) @@ -25,8 +26,11 @@ def parse_cmd_args(self, args): if os.path.exists(args.generate_m_value): self.generate_m_value(args.generate_m_value) else: - self.generate_m_value(os.path.join(self.curve_paths, args.generate_m_value)) - + curve_path = os.path.join(self.curve_paths, args.generate_m_value) + if os.path.exists(curve_path): + self.generate_m_value(curve_path) + else: + self.logger.info("The curve file doesn't exist. Please choose an appropriate file.") else: raise Exception("There were no arguments when running the application") @@ -48,6 +52,7 @@ def main(): stick knot's Bezier cure to match the stick knot", default=None, action="store") arguments = argument_parser.parse_args() + get_logger().debug("Subdivision-Generator Starting Up") application = CliApplication(application_path, application_name, arguments) diff --git a/logger.py b/logger.py index cc3c6a3..3d3bfaf 100644 --- a/logger.py +++ b/logger.py @@ -13,9 +13,18 @@ def get_logger(classname=None): if not os.path.exists(log_dir): os.makedirs(log_dir) - logging.basicConfig(filename="logs/generator_log.txt", level="DEBUG") + root = logging.getLogger() + if root.handlers: + for handler in root.handlers: + root.removeHandler(handler) + + logging.basicConfig(format='%(asctime)s: %(filename)s: %(funcName)s: %(levelname)s:\t %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filename="logs/generator_log.txt") if classname is None: classname = "Subdivision Generator" + logger = logging.getLogger(classname) + logger.setLevel(logging.INFO) + logger.addHandler(logging.StreamHandler()) + return logging.getLogger(classname) diff --git a/run.sh b/run.sh index 2089cea..48fffd9 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,3 @@ #!/bin/bash SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" -"$SCRIPT_DIR/user_interface/cli_application.py" $* +"$SCRIPT_DIR/cli_application.py" $*