logging: update logging levels and added new messages
This commit is contained in:
parent
98d1a3ba45
commit
63300e6012
1 changed files with 11 additions and 11 deletions
22
discorss.py
22
discorss.py
|
|
@ -116,16 +116,15 @@ class Discorss:
|
||||||
"Feed %s doesn't supply a published time, using updated time instead",
|
"Feed %s doesn't supply a published time, using updated time instead",
|
||||||
hook["name"],
|
hook["name"],
|
||||||
)
|
)
|
||||||
self.logger.debug("Feed url is %s", latest_post["url"])
|
|
||||||
# Hash the url of the latest post and use that to determine if it's been posted
|
# Hash the url of the latest post and use that to determine if it's been posted
|
||||||
# Yes, SHA3-512 is totally unnecessary for this purpose, but I love SHA3
|
# Yes, SHA3-512 is totally unnecessary for this purpose, but I love SHA3
|
||||||
self.logger.debug("About to hash %s ...", latest_post["url"])
|
self.logger.debug("About to hash %s ...", latest_post["link"])
|
||||||
try:
|
try:
|
||||||
new_hash = hashlib.sha3_512(
|
new_hash = hashlib.sha3_512(
|
||||||
bytes(latest_post["url"], "utf-8") # Removed time from hash
|
bytes(latest_post["link"], "utf-8") # Removed time from hash
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.logger.error("URL of %s isn't hashing correctly", hook["name"])
|
self.logger.error("URL %s isn't hashing correctly", hook["link"])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if new_hash in self._get_hash_history(hook):
|
if new_hash in self._get_hash_history(hook):
|
||||||
|
|
@ -173,7 +172,7 @@ class Discorss:
|
||||||
if not self.DRY_RUN:
|
if not self.DRY_RUN:
|
||||||
response = await self._post_webhook(hook, webhook_string, custom_header)
|
response = await self._post_webhook(hook, webhook_string, custom_header)
|
||||||
else:
|
else:
|
||||||
self.logger.debug(
|
self.logger.info(
|
||||||
"Dry run, not actually posting to webhook, faking return code 200"
|
"Dry run, not actually posting to webhook, faking return code 200"
|
||||||
)
|
)
|
||||||
response = SimpleNamespace(status_code=200)
|
response = SimpleNamespace(status_code=200)
|
||||||
|
|
@ -200,14 +199,14 @@ class Discorss:
|
||||||
for i, result in enumerate(results):
|
for i, result in enumerate(results):
|
||||||
hook = self.app_config["feeds"][i]
|
hook = self.app_config["feeds"][i]
|
||||||
if isinstance(result, asyncio.TimeoutError):
|
if isinstance(result, asyncio.TimeoutError):
|
||||||
self.logger.error(
|
self.logger.critical(
|
||||||
"Timed out processing feed %s after %d seconds",
|
"Timed out processing feed %s after %d seconds",
|
||||||
hook["name"],
|
hook["name"],
|
||||||
self.FEED_TIMEOUT_SECONDS,
|
self.FEED_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
if isinstance(result, requests.RequestException):
|
if isinstance(result, requests.RequestException):
|
||||||
self.logger.error(
|
self.logger.critical(
|
||||||
"Network error while processing feed %s: %s",
|
"Network error while processing feed %s: %s",
|
||||||
hook["name"],
|
hook["name"],
|
||||||
result,
|
result,
|
||||||
|
|
@ -223,7 +222,7 @@ class Discorss:
|
||||||
if result is None:
|
if result is None:
|
||||||
continue
|
continue
|
||||||
if "lasthash" not in hook:
|
if "lasthash" not in hook:
|
||||||
self.logger.info(
|
self.logger.debug(
|
||||||
"Feed %s has no existing hash, likely a new feed!", hook["name"]
|
"Feed %s has no existing hash, likely a new feed!", hook["name"]
|
||||||
)
|
)
|
||||||
hash_history = self._get_hash_history(hook)
|
hash_history = self._get_hash_history(hook)
|
||||||
|
|
@ -303,10 +302,11 @@ class Discorss:
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename=self.log_file_path,
|
filename=self.log_file_path,
|
||||||
encoding="utf-8",
|
encoding="utf-8",
|
||||||
level=logging.DEBUG,
|
level=logging.INFO,
|
||||||
datefmt="%m/%d/%Y %H:%M:%S",
|
datefmt="%m/%d/%Y %H:%M:%S",
|
||||||
format="%(asctime)s -> %(levelname)s: %(message)s",
|
format="%(asctime)s [%(threadName)s] -> %(levelname)s: %(message)s",
|
||||||
)
|
)
|
||||||
|
self.logger.info("========= Started discorss.py ==========")
|
||||||
return
|
return
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
|
@ -324,7 +324,7 @@ class Discorss:
|
||||||
self.app_config["lastupdate"] = self.now
|
self.app_config["lastupdate"] = self.now
|
||||||
with open(self.config_file_path, "w") as config_file:
|
with open(self.config_file_path, "w") as config_file:
|
||||||
json.dump(self.app_config, config_file, indent=4)
|
json.dump(self.app_config, config_file, indent=4)
|
||||||
|
self.logger.info("========= Ended discord.py =========")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue