diff --git a/discorss.py b/discorss.py index a77dd48..3419962 100755 --- a/discorss.py +++ b/discorss.py @@ -262,24 +262,25 @@ class Discorss: os.environ["TZ"] = "America/Toronto" time.tzset() self.now = time.mktime(time.localtime()) + # Set up logging + self.logger = logging.getLogger(__name__) + logging.basicConfig( + filename=self.log_file_path, + encoding="utf-8", + level=logging.WARNING, + datefmt="%m/%d/%Y %H:%M:%S", + format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s", + ) # Check for log and config files/paths, create empty directories if needed # TODO: change output to log file, as warning/error if not Path(self.log_dir).exists(): - print( - "No log file path exists. Yark! We'll try and make {}...".format( - self.log_dir - ) - ) + self.logger.warning("No log file path exists. Yark! We'll try and make %s...", self.log_dir) try: Path(self.log_dir).mkdir(parents=True, exist_ok=True) except FileExistsError: - print( - "The path {} already exists and is not a directory!".format( - self.log_dir - ) - ) + self.logger.critical("The path {} already exists and is not a directory!".format(self.log_dir)) if not Path(self.config_file_path).exists(): - print( + self.logger.warning( "No config file at {}! Snarf. We'll try and make {}...".format( self.config_file_path, self.config_dir ) @@ -287,7 +288,7 @@ class Discorss: try: Path(self.config_dir).mkdir(parents=True, exist_ok=True) except FileExistsError: - print( + self.warning.critical( "The config dir {} already exists and is not a directory! Please fix manually. Quitting!".format( self.config_dir ) @@ -297,20 +298,11 @@ class Discorss: # Loading the config file with open(self.config_file_path, "r") as config_file: self.app_config = json.load(config_file) - # Set up logging - self.logger = logging.getLogger(__name__) - logging.basicConfig( - filename=self.log_file_path, - encoding="utf-8", - level=logging.INFO, - datefmt="%m/%d/%Y %H:%M:%S", - format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s", - ) - self.logger.info("========= Started discorss.py ==========") return def process(self): self.setup() # Handle the config and log paths + self.logger.info("Starting DiscoRSS run...") try: last_check = self.app_config["lastupdate"] except KeyError: @@ -324,7 +316,6 @@ class Discorss: self.app_config["lastupdate"] = self.now with open(self.config_file_path, "w") as config_file: json.dump(self.app_config, config_file, indent=4) - self.logger.info("========= Ended discord.py =========") return