[Kimchi-devel] [PATCH] [Wok 6/6] Add status code to request log message

Lucio Correia luciojhc at linux.vnet.ibm.com
Thu Jun 9 20:59:09 UTC 2016


* Also, remove download field from filtering options.
* Update test case

Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 docs/API/logs.md     |  1 +
 src/wok/reqlogger.py | 10 +++++-----
 tests/test_api.py    |  2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/docs/API/logs.md b/docs/API/logs.md
index fcfb3b2..0cbabff 100644
--- a/docs/API/logs.md
+++ b/docs/API/logs.md
@@ -12,6 +12,7 @@
                Use "wok" or any plugin installed, like "kimchi".
         * req: Filter entries by type of request: "DELETE", "POST", "PUT".
                "GET" requests are not logged.
+        * status: Filter entries by HTTP response status: 200, 404, 500, etc.
         * user: Filter entries by user that performed the request.
         * ip: Filter entries by user IP address, i.e. 127.0.0.1
         * date: Filter entries by date of record in the format "YYYY-MM-DD"
diff --git a/src/wok/reqlogger.py b/src/wok/reqlogger.py
index 6f32c44..8fadbcf 100644
--- a/src/wok/reqlogger.py
+++ b/src/wok/reqlogger.py
@@ -34,16 +34,17 @@ from wok.utils import ascii_dict, remove_old_files
 
 
 # Log search setup
-FILTER_FIELDS = ['app', 'date', 'download', 'ip', 'req', 'user', 'time']
+FILTER_FIELDS = ['app', 'date', 'ip', 'req', 'status' 'user', 'time']
 LOG_DOWNLOAD_URI = "/data/logs/%s"
 LOG_DOWNLOAD_TIMEOUT = 6
-LOG_FORMAT = "[%(date)s %(time)s %(zone)s] %(req)-6s %(app)-11s %(ip)-15s " \
-             "%(user)s: %(message)s\n"
+LOG_FORMAT = "[%(date)s %(time)s %(zone)s] %(req)-6s %(status)s %(app)-11s " \
+             "%(ip)-15s %(user)s: %(message)s\n"
 RECORD_TEMPLATE_DICT = {
     'date': '',
     'time': '',
     'zone': '',
     'req': '',
+    'status': '',
     'app': '',
     'ip': '',
     'user': '',
@@ -157,6 +158,7 @@ class RequestParser(object):
         uri = None
         results = []
         records = self.getRecords()
+        download = filter_params.pop('download', False)
 
         # fail for unrecognized filter options
         for key in filter_params.keys():
@@ -164,8 +166,6 @@ class RequestParser(object):
                 filters = ", ".join(FILTER_FIELDS)
                 raise InvalidParameter("WOKLOG0001E", {"filters": filters})
 
-        download = filter_params.pop('download', False)
-
         # filter records according to parameters
         for record in records:
             if all(key in record and record[key] == val
diff --git a/tests/test_api.py b/tests/test_api.py
index 79f9af5..bcf34cb 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -84,7 +84,7 @@ class APITests(unittest.TestCase):
         self.assertGreaterEqual(records, 1)
         for record in records:
             keys = [u'zone', u'ip', u'app', u'req', u'user', u'time', u'date',
-                    u'message']
+                    u'message', u'status']
             self.assertEquals(sorted(keys), sorted(record.keys()))
 
             # Test search by app
-- 
1.9.1




More information about the Kimchi-devel mailing list