mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-24 06:44:19 +00:00
Improve logging messages
This commit is contained in:
parent
8a748b3918
commit
c5bf4b544a
2 changed files with 11 additions and 8 deletions
13
core.py
13
core.py
|
@ -42,8 +42,8 @@ def main():
|
||||||
# Copy the template file to the config file
|
# Copy the template file to the config file
|
||||||
user_cfg_file.write(template_cfg_file.read())
|
user_cfg_file.write(template_cfg_file.read())
|
||||||
|
|
||||||
print("A config file has been created in config/config.toml."
|
log.fatal("A config file has been created in config/config.toml."
|
||||||
" Edit it with your configuration, then restart this script.")
|
" Customize it, then restart greed!")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Compare the template config with the user-made one
|
# Compare the template config with the user-made one
|
||||||
|
@ -52,8 +52,10 @@ def main():
|
||||||
template_cfg = nuconfig.NuConfig(template_cfg_file)
|
template_cfg = nuconfig.NuConfig(template_cfg_file)
|
||||||
user_cfg = nuconfig.NuConfig(user_cfg_file)
|
user_cfg = nuconfig.NuConfig(user_cfg_file)
|
||||||
if not template_cfg.cmplog(user_cfg):
|
if not template_cfg.cmplog(user_cfg):
|
||||||
log.fatal("Invalid configuration, refusing to start.")
|
log.fatal("There were errors while parsing the config.toml file. Please fix them and restart greed!")
|
||||||
exit(2)
|
exit(2)
|
||||||
|
else:
|
||||||
|
log.debug("Configuration parsed successfully!")
|
||||||
|
|
||||||
# Finish logging setup
|
# Finish logging setup
|
||||||
logging.root.setLevel(user_cfg["Logging"]["level"])
|
logging.root.setLevel(user_cfg["Logging"]["level"])
|
||||||
|
@ -109,9 +111,10 @@ def main():
|
||||||
# Main loop of the program
|
# Main loop of the program
|
||||||
while True:
|
while True:
|
||||||
# Get a new batch of 100 updates and mark the last 100 parsed as read
|
# Get a new batch of 100 updates and mark the last 100 parsed as read
|
||||||
log.debug("Getting updates from Telegram")
|
update_timeout = user_cfg["Telegram"]["long_polling_timeout"]
|
||||||
|
log.debug(f"Getting updates from Telegram with a timeout of {update_timeout} seconds")
|
||||||
updates = bot.get_updates(offset=next_update,
|
updates = bot.get_updates(offset=next_update,
|
||||||
timeout=int(user_cfg["Telegram"]["long_polling_timeout"]))
|
timeout=update_timeout)
|
||||||
# Parse all the updates
|
# Parse all the updates
|
||||||
for update in updates:
|
for update in updates:
|
||||||
# If the update is a message...
|
# If the update is a message...
|
||||||
|
|
|
@ -25,12 +25,12 @@ class NuConfig:
|
||||||
def __cmplog_log(compare_report: CompareReport, root: str = "") -> None:
|
def __cmplog_log(compare_report: CompareReport, root: str = "") -> None:
|
||||||
"""The recursive portion of :meth:`.cmplog`."""
|
"""The recursive portion of :meth:`.cmplog`."""
|
||||||
for item in compare_report.get("__missing__", []):
|
for item in compare_report.get("__missing__", []):
|
||||||
log.error(f"Missing config key: {root}{item}")
|
log.error(f"Missing key: {root}{item}")
|
||||||
|
|
||||||
for item in compare_report.get("__invalid__", []):
|
for item in compare_report.get("__invalid__", []):
|
||||||
log.error(f"Invalid config key: {root}{item}")
|
log.error(f"Key has an invalid type: {root}{item}")
|
||||||
|
|
||||||
for key, value in compare_report:
|
for key, value in compare_report.items():
|
||||||
if key == "__missing__" or key == "__invalid__":
|
if key == "__missing__" or key == "__invalid__":
|
||||||
continue
|
continue
|
||||||
NuConfig.__cmplog_log(value, root=f"{root}{key}.")
|
NuConfig.__cmplog_log(value, root=f"{root}{key}.")
|
||||||
|
|
Loading…
Reference in a new issue