Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adjustment of logging level #133

Merged
merged 2 commits into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions keepa/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def wrapper(target):


log = logging.getLogger(__name__)
log.setLevel("DEBUG")

# hardcoded ordinal time from
KEEPA_ST_ORDINAL = np.datetime64("2011-01-01")
Expand Down Expand Up @@ -359,6 +358,10 @@ class Keepa:
seconds. Setting this to 0 disables the timeout, but will
cause any request to hang indefiantly should keepa.com be down

logging_level: string, optional
Logging level to use. Default is 'DEBUG'. Other options are
'INFO', 'WARNING', 'ERROR', and 'CRITICAL'.

Examples
--------
Create the api object.
Expand Down Expand Up @@ -391,13 +394,20 @@ class Keepa:

"""

def __init__(self, accesskey, timeout=10):
def __init__(self, accesskey, timeout=10, logging_level="DEBUG"):
"""Initialize server connection."""
self.accesskey = accesskey
self.status = None
self.tokens_left = 0
self._timeout = timeout

# Set up logging
levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
if logging_level not in levels:
raise TypeError(
"logging_level must be one of: " + ", ".join(levels)
)
log.setLevel(logging_level)
# Store user's available tokens
log.info("Connecting to keepa using key ending in %s", accesskey[-6:])
self.update_status()
Expand Down