diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-08-04 17:39:11 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-08-04 17:39:11 +0300 |
commit | e291a7a172300e5d4ccdaabde3b52af14034590c (patch) | |
tree | 31b41351a5212d16eef25f5db478be2fa4899387 | |
parent | da82fc487b2a6d7975ea845e07bdf6b593dc1db4 (diff) | |
download | apifw-e291a7a172300e5d4ccdaabde3b52af14034590c.tar.gz |
Add: update NEWS
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | apifw/bottleapp.py | 3 | ||||
-rw-r--r-- | apifw/http.py | 5 | ||||
-rw-r--r-- | apitest.py | 6 |
4 files changed, 14 insertions, 2 deletions
@@ -7,6 +7,8 @@ This file summarizes changes between releases of `apifw`. Version 0.6+git, not yet released --------------------------------- +* Add "counter" argument to Bottle application, for countint HTTP + transaction. Version 0.6, released 2017-08-04 --------------------------------- diff --git a/apifw/bottleapp.py b/apifw/bottleapp.py index b248858..9b45073 100644 --- a/apifw/bottleapp.py +++ b/apifw/bottleapp.py @@ -208,7 +208,7 @@ class BottleApplication: return content_type, body -def create_bottle_application(api, logger, config): +def create_bottle_application(api, counter, logger, config): # Create a new bottle.Bottle application, set it up, and return it # so that gunicorn can execute it from the main program. @@ -216,6 +216,7 @@ def create_bottle_application(api, logger, config): app = BottleApplication(bottleapp, api) plugin = BottleLoggingPlugin() + plugin.set_transaction_counter(counter) if logger: plugin.set_dict_logger(logger) app.add_plugin(plugin) diff --git a/apifw/http.py b/apifw/http.py index 6b6a1e2..420ca04 100644 --- a/apifw/http.py +++ b/apifw/http.py @@ -42,6 +42,7 @@ class HttpTransaction: def __init__(self): self._logger = lambda log, **kwargs: None + self._counter = lambda: None def construct_request_log(self): # Override in subclass, as necessary. @@ -60,6 +61,9 @@ class HttpTransaction: # Set function to actually do logging. self._logger = logger + def set_transaction_counter(self, counter): + self._counter = counter + def _log_request(self): log = { 'msg_type': 'http-request', @@ -88,6 +92,7 @@ class HttpTransaction: def perform_transaction(self, callback, *args, **kwargs): try: + self._counter() self._log_request() data = callback(*args, **kwargs) self.amend_response() @@ -99,6 +99,10 @@ def dict_logger(log, stack_info=None): logging.info('Traceback', exc_info=True) +def counter(): + pass + + logfile = os.environ.get('APITEST_LOG') if logfile: logging.basicConfig(filename=logfile, level=logging.DEBUG) @@ -134,7 +138,7 @@ config = { # hopefully don't need to care, how the magic works. api = Api() -app = apifw.create_bottle_application(api, dict_logger, config) +app = apifw.create_bottle_application(api, counter, dict_logger, config) # If we are running this program directly with Python, and not via # gunicorn, we can use the Bottle built-in debug server, which can |