Skip to content

Commit

Permalink
Merge pull request #606 from ScilifelabDataCentre/DDS-1398-reduce-deb…
Browse files Browse the repository at this point in the history
…ug-level-logs-from-cli

Reduce debug level logs
  • Loading branch information
i-oden authored Feb 10, 2023
2 parents d7306f4 + f139053 commit 8db3f1e
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,6 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe
# Sprint (2023-02-03 - 2023-02-17)

- Workflow: Lint yaml files ([#605](https://github.com/ScilifelabDataCentre/dds_cli/pull/605))
- Logging: Reduce debug level logging and remove logging from root ([#606](https://github.com/ScilifelabDataCentre/dds_cli/pull/606))
- Add separate executables for Ubuntu latest (currently 22.04) and Ubuntu 20.04 ([#604](https://github.com/ScilifelabDataCentre/dds_cli/pull/604))
- Bug: PyInstaller command not valid for Linux and macOS ([#612](https://github.com/ScilifelabDataCentre/dds_cli/pull/612))
10 changes: 7 additions & 3 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# START LOGGING CONFIG ###################################################### START LOGGING CONFIG #
####################################################################################################

LOG = logging.getLogger()
LOG = logging.getLogger("dds_cli")

# Configuration for rich-click output
click.rich_click.MAX_WIDTH = 100
Expand Down Expand Up @@ -160,7 +160,10 @@ def dds_main(click_ctx, verbose, log_file, no_prompt, token_path):
log_fh = logging.FileHandler(log_file, encoding="utf-8")
log_fh.setLevel(logging.DEBUG)
log_fh.setFormatter(
logging.Formatter("[%(asctime)s] %(name)-20s [%(levelname)-7s] %(message)s")
logging.Formatter(
fmt="[%(asctime)s] %(name)-15s %(lineno)-5s [%(levelname)-7s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
)
LOG.addHandler(log_fh)

Expand Down Expand Up @@ -250,6 +253,7 @@ def list_projects_and_contents(

# If didn't enter anything, convert to None and exit
except (KeyboardInterrupt, AssertionError):
LOG.debug("No project entered, exiting.")
break

# List all files in a project if we know a project ID
Expand Down Expand Up @@ -399,7 +403,7 @@ def login(click_ctx, totp, allow_group):
token_path=click_ctx.get("TOKEN_PATH"), totp=totp, allow_group=allow_group
):
# Authentication token renewed in the init method.
LOG.info("[green] :white_check_mark: Authentication token created![/green]")
LOG.info(f"[green] :white_check_mark: Authentication successful![/green]")
except (
dds_cli.exceptions.APIError,
dds_cli.exceptions.AuthenticationError,
Expand Down
1 change: 0 additions & 1 deletion dds_cli/account_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def get_user_info(self):
for field in response.get("info", []):
if isinstance(response["info"][field], str):
response["info"][field] = rich.markup.escape(response["info"][field])
LOG.debug(response)

info = response.get("info")
if info:
Expand Down
3 changes: 2 additions & 1 deletion dds_cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def check(self):
token_file = user.TokenFile(token_path=self.token_path)
if token_file.file_exists():
token = token_file.read_token()
token_file.token_report(token=token)
if token:
token_file.token_report(token=token)
else:
LOG.info(
"[red]No saved token found, or token has expired. Authenticate yourself with `dds auth login` to use this functionality![/red]"
Expand Down
2 changes: 1 addition & 1 deletion dds_cli/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __str__(self):
class DDSCLIException(click.ClickException):
"""Base exception for click in DDS."""

def __init__(self, message, sign=":warning-emoji:", show_emojis=True):
def __init__(self, message, sign=":warning-emoji:", show_emojis=False):
"""Init base exception."""
self.message = message
self.show_emojis = show_emojis
Expand Down
1 change: 0 additions & 1 deletion dds_cli/file_encryptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ def verify_checksum(file: pathlib.Path, correct_checksum):
if checksum.hexdigest() == correct_checksum:
verified, error = (True, "File integrity verified.")
LOG.info("Checksum verification successful. File integrity verified.")
LOG.debug(error)
else:
error = "Checksum verification failed. File compromised."
LOG.warning(error)
Expand Down
2 changes: 0 additions & 2 deletions dds_cli/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ def delete_tempdir(directory: pathlib.Path):

# Iterate through any existing subdirectories - recursive
LOG.debug(f"Any in directory? {any(directory.iterdir())}")
for x in directory.iterdir():
LOG.debug(x)
if any(directory.iterdir()):
for p in directory.iterdir():
if p.is_dir():
Expand Down
2 changes: 0 additions & 2 deletions dds_cli/file_handler_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ def __collect_file_info_remote(self, all_paths, token):
}
for x, y in files.items()
}
LOG.debug(f"Data (files):\n {data}")

# Save info on files in a specific folder and return
for x, y in folder_contents.items():
LOG.debug(f"{x}")
data.update(
{
self.local_destination
Expand Down
4 changes: 2 additions & 2 deletions dds_cli/s3_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def connect(self):
except (boto3.exceptions.Boto3Error, botocore.exceptions.BotoCoreError) as err:
LOG.warning(f"S3 connection failed: {err}")
raise

LOG.debug(f"Resource :{self.resource}")
else:
LOG.debug(f"Connected to S3.")
return resource

# Static methods ############ Static methods #
Expand Down
13 changes: 9 additions & 4 deletions dds_cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __retrieve_token(self, totp: str = None, allow_group: bool = False):
"""Fetch saved token from file otherwise authenticate user and saves the new token."""
token_file = TokenFile(token_path=self.token_path, allow_group=allow_group)
if not self.force_renew_token:
LOG.debug("Retrieving token.")
LOG.debug("Retrieving token...")

# Get token from file
try:
Expand All @@ -89,7 +89,7 @@ def __retrieve_token(self, totp: str = None, allow_group: bool = False):

def __authenticate_user(self, totp: str = None):
"""Authenticates the username and password via a call to the API."""
LOG.debug("Starting authentication on the API.")
LOG.debug("Starting authentication on the API...")

if self.no_prompt:
raise exceptions.AuthenticationError(
Expand Down Expand Up @@ -136,6 +136,7 @@ def __authenticate_user(self, totp: str = None):
)

else:
LOG.debug(f"2FA method: {'TOTP' if totp_enabled else 'HOTP'}")
if totp_enabled:
LOG.info(
"Please enter the one-time authentication code from your authenticator app."
Expand Down Expand Up @@ -232,7 +233,11 @@ def __init__(self, token_path=None, allow_group: bool = False):
def read_token(self):
"""Attempts to fetch a valid token from the token file.
Returns None if no valid token can be found."""
Returns None if no valid token can be found.
Debug, not warning. Run prior to logging configured.
"""
LOG.debug("Attempting to retrieve token from file...")

if not self.file_exists():
LOG.debug(f"Token file {self.token_file} does not exist.")
Expand All @@ -247,7 +252,7 @@ def read_token(self):
raise exceptions.TokenNotFoundError(message="Token file is empty.")

if self.token_expired(token=token):
LOG.debug("No token retrieved from file, will fetch new token from API")
LOG.debug("The token has expired, reauthentication required.")
return None

LOG.debug("Token retrieved from file.")
Expand Down
2 changes: 0 additions & 2 deletions dds_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
console = rich.console.Console()
stderr_console = rich.console.Console(stderr=True)

LOG = logging.getLogger(__name__)

# Classes


Expand Down

0 comments on commit 8db3f1e

Please sign in to comment.