Skip to content

Commit

Permalink
use LOGGER
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Mar 6, 2024
1 parent f438621 commit 16ffcb9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions rest_tools/server/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .decorators import catch_error
from .stats import RouteStats

logger = logging.getLogger('rest')
LOGGER = logging.getLogger('rest')


def RestHandlerSetup(config={}):
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self, *args, **kwargs) -> None:
try:
super().__init__(*args, **kwargs)
except Exception:
logger.error('error', exc_info=True)
LOGGER.error('error', exc_info=True)

def initialize(self, debug=False, auth=None, auth_url=None, module_auth_key='', server_header='', route_stats=None, **kwargs):
super().initialize(**kwargs)
Expand Down Expand Up @@ -142,29 +142,29 @@ def get_current_user(self):
type, token = self.request.headers['Authorization'].split(' ', 1)
if type.lower() != 'bearer':
raise Exception('bad header type')
logger.debug('token: %r', token)
LOGGER.debug('token: %r', token)
data = self.auth.validate(token)
self.auth_data = data
self.auth_key = token
return data['sub']
# Auth Failed
except Exception:
if self.debug and 'Authorization' in self.request.headers:
logger.info('Authorization: %r', self.request.headers['Authorization'])
logger.info('failed auth', exc_info=True)
LOGGER.info('Authorization: %r', self.request.headers['Authorization'])
LOGGER.info('failed auth', exc_info=True)

return None

@wtt.evented()
def prepare(self):
"""Prepare before http-method request handlers."""
logger.debug(f"{self.request.method} [{self.__class__.__name__}]")
LOGGER.debug(f"{self.request.method} [{self.__class__.__name__}]")

if self.route_stats is not None:
stat = self.route_stats[self.request.path]
if stat.is_overloaded():
backoff = stat.get_backoff_time()
logger.warn('Server is overloaded, backoff %r', backoff)
LOGGER.warn('Server is overloaded, backoff %r', backoff)
self.set_header('Retry-After', backoff)
raise tornado.web.HTTPError(503, reason="server overloaded")
self.start_time = time.time()
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_current_user(self):
if not username:
username = self.auth_data.get('upn', None)
if not username:
logger.info('could not find auth username')
LOGGER.info('could not find auth username')
return username


Expand All @@ -283,7 +283,7 @@ def get_current_user(self):
return data['sub']
# Auth Failed
except Exception:
logger.debug('failed auth', exc_info=True)
LOGGER.debug('failed auth', exc_info=True)

return None

Expand Down Expand Up @@ -400,7 +400,7 @@ async def get_authenticated_user(
self.auth.validate(ret['access_token'])
except Exception:
if self.debug:
logger.debug(f'bad token: {ret}')
LOGGER.debug(f'bad token: {ret}')
raise
return ret

Expand Down

0 comments on commit 16ffcb9

Please sign in to comment.