[Kimchi-devel] [PATCH] [Wok 2/3] Add support and translate user request log messages

Lucio Correia luciojhc at linux.vnet.ibm.com
Fri May 13 18:05:08 UTC 2016


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 src/wok/control/base.py | 17 ++++++++++++-----
 src/wok/i18n.py         |  6 ++++++
 src/wok/root.py         | 13 +++++++++----
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/src/wok/control/base.py b/src/wok/control/base.py
index 29b43ac..be5f618 100644
--- a/src/wok/control/base.py
+++ b/src/wok/control/base.py
@@ -33,13 +33,14 @@ from wok.control.utils import validate_params
 from wok.exception import InvalidOperation, InvalidParameter
 from wok.exception import MissingParameter, NotFoundError
 from wok.exception import OperationFailed, UnauthorizedError, WokException
+from wok.message import WokMessage
 from wok.reqlogger import RequestRecord
 from wok.utils import get_plugin_from_request, utf8_dict, wok_log
 
 
 # Default request log messages
-COLLECTION_DEFAULT_LOG = "request on collection"
-RESOURCE_DEFAULT_LOG = "request on resource"
+COLLECTION_DEFAULT_LOG = "WOKCOL0001L"
+RESOURCE_DEFAULT_LOG = "WOKRES0001L"
 
 LOG_DISABLED_METHODS = ['GET']
 
@@ -138,9 +139,11 @@ class Resource(object):
                 action_result = action_fn(*model_args)
 
                 # log request
+                code = self.getRequestMessage(method, action_name)
                 reqParams = utf8_dict(self.log_args, request)
+                msg = WokMessage(code, reqParams).get_text(prepend_code=False)
                 RequestRecord(
-                    self.getRequestMessage(method, action_name) % reqParams,
+                    msg,
                     app=get_plugin_from_request(),
                     req=method,
                     user=cherrypy.session.get(USER_NAME, 'N/A')
@@ -218,8 +221,10 @@ class Resource(object):
 
         # log request
         if method not in LOG_DISABLED_METHODS:
+            code = self.getRequestMessage(method)
+            msg = WokMessage(code, self.log_args).get_text(prepend_code=False)
             RequestRecord(
-                self.getRequestMessage(method) % self.log_args,
+                msg,
                 app=get_plugin_from_request(),
                 req=method,
                 user=cherrypy.session.get(USER_NAME, 'N/A')
@@ -437,9 +442,11 @@ class Collection(object):
                 result = self.create(params, *args)
 
                 # log request
+                code = self.getRequestMessage(method)
                 reqParams = utf8_dict(self.log_args, params)
+                msg = WokMessage(code, reqParams).get_text(prepend_code=False)
                 RequestRecord(
-                    self.getRequestMessage(method) % reqParams,
+                    msg,
                     app=get_plugin_from_request(),
                     req=method,
                     user=cherrypy.session.get(USER_NAME, 'N/A')
diff --git a/src/wok/i18n.py b/src/wok/i18n.py
index 5a2876f..d3342fc 100644
--- a/src/wok/i18n.py
+++ b/src/wok/i18n.py
@@ -54,4 +54,10 @@ messages = {
     "WOKUTILS0002E": _("Timeout while running command '%(cmd)s' after %(seconds)s seconds"),
     "WOKUTILS0004E": _("Invalid data value '%(value)s'"),
     "WOKUTILS0005E": _("Invalid data unit '%(unit)s'"),
+
+    # These messages (ending with L) are for user log purposes
+    "WOKCOL0001L": _("Request on collection"),
+    "WOKRES0001L": _("Request on resource"),
+    "WOKROOT0001L": _("User '%(username)s' login"),
+    "WOKROOT0002L": _("User '%(username)s' logout"),
 }
diff --git a/src/wok/root.py b/src/wok/root.py
index d1a2cc9..29ea657 100644
--- a/src/wok/root.py
+++ b/src/wok/root.py
@@ -32,14 +32,15 @@ from wok.control import sub_nodes
 from wok.control.base import Resource
 from wok.control.utils import parse_request
 from wok.exception import MissingParameter, OperationFailed
+from wok.message import WokMessage
 from wok.reqlogger import RequestRecord
 from wok.utils import get_plugin_from_request
 
 
 ROOT_REQUESTS = {
     'POST': {
-        'login': "User '%(username)s' login",
-        'logout': "User '%(username)s' logout",
+        'login': "WOKROOT0001L",
+        'logout': "WOKROOT0002L",
     },
 }
 
@@ -165,8 +166,10 @@ class WokRoot(Root):
             raise cherrypy.HTTPError(401)
         finally:
             method = 'POST'
+            code = self.getRequestMessage(method, 'login')
+            msg = WokMessage(code, params).get_text(prepend_code=False)
             RequestRecord(
-                self.getRequestMessage(method, 'login') % params,
+                msg,
                 app=get_plugin_from_request(),
                 req=method,
                 user=cherrypy.session.get(auth.USER_NAME, 'N/A')
@@ -177,9 +180,11 @@ class WokRoot(Root):
     @cherrypy.expose
     def logout(self):
         method = 'POST'
+        code = self.getRequestMessage(method, 'logout')
         params = {'username': cherrypy.session.get(auth.USER_NAME, 'N/A')}
+        msg = WokMessage(code, params).get_text(prepend_code=False)
         RequestRecord(
-            self.getRequestMessage(method, 'logout') % params,
+            msg,
             app=get_plugin_from_request(),
             req=method,
             user=params['username']
-- 
1.9.1




More information about the Kimchi-devel mailing list