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

log output as json #437

Merged
merged 1 commit into from
Jan 31, 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
7 changes: 4 additions & 3 deletions espn_api/utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
import sys
import json

class Logger(object):
def __init__(self, name: str, debug=False):
level = logging.DEBUG if debug else logging.INFO
self.logging = logging.getLogger(name)

# if logger already exists don't add handlers
if len(self.logging.handlers):
self.logging.handlers[0].setLevel(level)
Expand All @@ -18,9 +19,9 @@ def __init__(self, name: str, debug=False):

self.logging.addHandler(handler)
self.logging.setLevel(level)

def log_request(self, endpoint: str, response: dict, params: dict = None, headers: dict = None):
log = f'ESPN API Request: url: {endpoint} params: {params} headers: {headers} \nESPN API Response: {response}'
log = f'ESPN API Request: url: {endpoint} params: {params} headers: {headers} \nESPN API Response: {json.dumps(response)}'
self.logging.debug(log)


Expand Down