Skip to content

Commit

Permalink
MAINT: verbose logging flow for method selector to help me debug
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLLentz committed Mar 20, 2024
1 parent 86919fe commit 08c058e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pmpsdb_client/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def _main(args: argparse.Namespace) -> int:
print(version)
return 0
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s %(levelname)s: %(name)s %(message)s",
)
else:
logging.basicConfig(
level=logging.INFO,
Expand Down
6 changes: 6 additions & 0 deletions pmpsdb_client/plc_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,27 @@ def list_file_info(
data_method = DataMethod.unk

if data_method == DataMethod.ssh:
logger.debug("Using cached ssh method to list files for %s", hostname)
return ssh_data.list_file_info(hostname=hostname, directory=directory)
elif data_method == DataMethod.ftp:
logger.debug("Using cached ftp method to list files for %s", hostname)
return ftp_data.list_file_info(hostname=hostname, directory=directory)
elif data_method == DataMethod.unk:
logger.debug("Connection method unknown, check if ssh method works for %s", hostname)
try:
file_info = ssh_data.list_file_info(hostname=hostname, directory=directory)
except Exception:
logger.debug("ssh failed, check if ftp method works for %s", hostname)
try:
file_info = ftp_data.list_file_info(hostname=hostname, directory=directory)
except Exception:
raise RuntimeError(f"Cannot get data method for {hostname}")
else:
logger.debug("Cache %s method as ftp", hostname)
plc_mapping[hostname] = DataMethod.ftp
return file_info
else:
logger.debug("Cache %s method as ssh", hostname)
plc_mapping[hostname] = DataMethod.ssh
return file_info
else:
Expand Down

0 comments on commit 08c058e

Please sign in to comment.