Skip to content

Commit

Permalink
Merge pull request #437 from dtcarls/master
Browse files Browse the repository at this point in the history
log output as json
  • Loading branch information
cwendt94 committed Jan 31, 2023
2 parents 0e04b0d + 4ba1f87 commit 41780f4
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit 41780f4

Please sign in to comment.