Skip to content

Commit

Permalink
Add a mechanism for overriding individual logging levels in the `init…
Browse files Browse the repository at this point in the history
…_logging` function, which is a root logger initializer and therefore is "all-inclusive" by default. This allows us to squelch some messages (from globus_sdk in particular) that we don't really need users to be seeing.

Fix an issue with hatrac-cli.py that wasn't allowing an oauth2_token CLI parameter to be properly passed as the credential.
  • Loading branch information
mikedarcy committed Jun 22, 2021
1 parent db20fc8 commit 5f3892f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 7 additions & 5 deletions deriva/core/hatrac_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import sys
import traceback
from deriva.core import __version__ as VERSION, BaseCLI, DerivaPathError, HatracStore, HatracHashMismatch, \
get_credential, format_exception, DEFAULT_CHUNK_SIZE
get_credential, format_credential, format_exception, DEFAULT_CHUNK_SIZE
from deriva.core.utils import eprint, mime_utils as mu


Expand Down Expand Up @@ -120,9 +120,9 @@ def __init__(self, description, epilog):
delobj_parser.set_defaults(func=self.delobj)

@staticmethod
def _get_credential(host_name, token=None):
if token:
return {"cookie": "webauthn={t}".format(t=token)}
def _get_credential(host_name, token=None, oauth2_token=None):
if token or oauth2_token:
return format_credential(token=token, oauth2_token=oauth2_token)
else:
return get_credential(host_name)

Expand All @@ -131,7 +131,9 @@ def _post_parser_init(self, args):
"""
self.host = args.host if args.host else 'localhost'
self.resource = args.resource
self.store = HatracStore('https', args.host, DerivaHatracCLI._get_credential(self.host, args.token))
self.store = HatracStore('https', args.host, DerivaHatracCLI._get_credential(self.host,
token=args.token,
oauth2_token=args.oauth2_token))

def list(self, args):
"""Implements the list sub-command.
Expand Down
18 changes: 14 additions & 4 deletions deriva/core/utils/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
OAUTH2_SCOPES_KEY: {}
}
DEFAULT_CREDENTIAL = {}
DEFAULT_LOGGER_OVERRIDES = {
"globus_sdk.auth": logging.WARNING,
"globus_sdk.authorizers": logging.WARNING,
"boto3": logging.WARNING,
"botocore": logging.WARNING,
}


class NotModified (ValueError):
Expand Down Expand Up @@ -150,12 +156,16 @@ def init_logging(level=logging.INFO,
log_format=None,
file_path=None,
file_mode='w',
capture_warnings=True):
capture_warnings=True,
logger_config=DEFAULT_LOGGER_OVERRIDES):
add_logging_level("TRACE", logging.DEBUG-5)
logging.captureWarnings(capture_warnings)
if log_format is None:
log_format = "[%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s:%(funcName)s()] %(message)s" \
log_format = "[%(asctime)s - %(levelname)s - %(name)s:%(filename)s:%(lineno)s:%(funcName)s()] %(message)s" \
if level <= logging.DEBUG else "%(asctime)s - %(levelname)s - %(message)s"
if level > logging.DEBUG:
# If we're above DEBUG level, allow for reconfiguration of module-specific logging levels
[logging.getLogger(name).setLevel(level) for name, level in logger_config.items()]
if file_path:
logging.basicConfig(filename=file_path, filemode=file_mode, level=level, format=log_format)
else:
Expand Down Expand Up @@ -342,8 +352,8 @@ def format_credential(token=None, oauth2_token=None, username=None, password=Non
return credential


def bootstrap():
init_logging()
def bootstrap(logging_level=logging.INFO):
init_logging(level=logging_level)
read_config(create_default=True)
read_credential(create_default=True)

Expand Down

0 comments on commit 5f3892f

Please sign in to comment.