Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion perimeterx/px_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, config_dict):
self._auth_token = config_dict.get('auth_token', None)
self._cookie_key = config_dict.get('cookie_key', None)
self.__instantiate_user_defined_handlers(config_dict)
self._logger = Logger(debug_mode)
self._logger = Logger(debug_mode, app_id)

@property
def module_mode(self):
Expand Down
11 changes: 4 additions & 7 deletions perimeterx/px_logger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
class Logger(object):
def __init__(self, debug=False):
def __init__(self, debug, app_id):
self.debug_mode = debug
self.app_id = app_id

def debug(self, message):
if self.debug_mode:
print '[PerimeterX DEBUG]: ' + message

def info(self, message):
if self.debug_mode:
print '[PerimeterX INFO]: ' + message
print '[PerimeterX DEBUG][{}]: '.format(self.app_id) + message

def error(self, message):
print '[PerimeterX ERROR]: ' + message
print '[PerimeterX ERROR][{}]: '.format(self.app_id) + message
2 changes: 1 addition & 1 deletion perimeterx/px_proxy_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def send_reverse_xhr_request(self, config, ctx, start_response, body):

if response.status_code >= 400:
body, content_type = self.return_default_response(uri)
px_logger.Logger.debug('error reversing the http call ' + response.reason)
self._logger.debug('error reversing the http call ' + response.reason)
start_response('200 OK', [content_type])
return body
self.handle_proxy_response(response, start_response)
Expand Down
9 changes: 6 additions & 3 deletions tests/px_blocker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from perimeterx.px_blocker import PXBlocker


import os
import unittest
from perimeterx.px_config import PxConfig
from perimeterx.px_context import PxContext
Expand Down Expand Up @@ -36,8 +36,10 @@ def test_handle_blocking(self):
ctx.uuid = px_uuid
px_config = PxConfig({'app_id': 'PXfake_app_ip'})
message, _, _ = px_blocker.handle_blocking(ctx, px_config)
with open('./px_blocking_messages/blocking.txt', 'r') as myfile:
working_dir = os.path.dirname(os.path.realpath(__file__))
with open(working_dir + '/px_blocking_messages/blocking.txt', 'r') as myfile:
blocking_message = myfile.read()

self.assertEqual(message, blocking_message)

def test_handle_ratelimit(self):
Expand All @@ -55,7 +57,8 @@ def test_handle_ratelimit(self):
ctx.block_action = 'r'
message, _, _ = px_blocker.handle_blocking(ctx, config)
blocking_message = None
with open('./px_blocking_messages/ratelimit.txt', 'r') as myfile:
working_dir = os.path.dirname(os.path.realpath(__file__))
with open(working_dir + '/px_blocking_messages/ratelimit.txt', 'r') as myfile:
blocking_message = myfile.read()
self.assertEqual(message, blocking_message)

Expand Down