PyJSONProxy

simple proxy and scraper
git clone https://git.ce9e.org/PyJSONProxy.git

commit
b1c1ec307c015c05642ccbf28a9eddbc9c81ae64
parent
d32bbbe584e5048dac4cd54a0a1c4427ae088fa2
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2015-12-06 22:29
Fix logger

Diffstat

M jsonproxy/__init__.py 3 +--
M jsonproxy/web.py 13 +++++++++++--

2 files changed, 12 insertions, 4 deletions


diff --git a/jsonproxy/__init__.py b/jsonproxy/__init__.py

@@ -43,8 +43,7 @@ def async_cache(maxsize=128):
   43    43 
   44    44 @async_cache()
   45    45 def _request(method, url):
   46    -1 	app.logger.info(method, url)
   47    -1 	print(method, url)
   -1    46 	app.logger.info('{}:{}'.format(method, url))
   48    47 	response = yield from aiohttp.request(method, url)
   49    48 	if response.status != 200:
   50    49 		abort(response.status)

diff --git a/jsonproxy/web.py b/jsonproxy/web.py

@@ -52,9 +52,16 @@ class Application:
   52    52 		self.name = name
   53    53 		self.loop = asyncio.get_event_loop()
   54    54 		self.app = web.Application(loop=self.loop)
   55    -1 		self.logger = logging
   56    55 		self.config = {}
   57    -1 		self.debug = False  # NOTE: does not do anything yet
   -1    56 		self.debug = False
   -1    57 
   -1    58 		self.logger = logging.getLogger(self.name)
   -1    59 		self.logger.setLevel(logging.INFO)
   -1    60 
   -1    61 		consoleHandler = logging.StreamHandler()
   -1    62 		formatter = logging.Formatter('%(asctime)s - %(message)s')
   -1    63 		consoleHandler.setFormatter(formatter)
   -1    64 		self.logger.addHandler(consoleHandler)
   58    65 
   59    66 	def config_from_file(self, path):
   60    67 		with open(path) as fh:
@@ -76,6 +83,8 @@ class Application:
   76    83 		return decorator
   77    84 
   78    85 	def run(self, host='localhost', port=5000):
   -1    86 		if self.debug:
   -1    87 			self.logger.setLevel(logging.DEBUG)
   79    88 		server = self.loop.create_server(self.app.make_handler(), host, port)
   80    89 		self.loop.run_until_complete(server)
   81    90 		self.logger.info("Server started at http://{}:{}".format(host, port))