Xapps now have an accessible mdc logger. 48/2848/1
authorTommy Carpenter <tc677g@att.com>
Wed, 18 Mar 2020 14:34:28 +0000 (10:34 -0400)
committerTommy Carpenter <tc677g@att.com>
Wed, 18 Mar 2020 14:34:42 +0000 (10:34 -0400)
Issue-ID: RIC-228
Change-Id: Ic1a4a6931398535821db238ed0e67c8181c163bd
Signed-off-by: Tommy Carpenter <tc677g@att.com>
docs/release-notes.rst
examples/Dockerfile-Ping
examples/Dockerfile-Pong
examples/ping_xapp.py
examples/pong_xapp.py
ricxappframe/xapp_frame.py
setup.py
tests/test_xapps.py

index 8491cf4..a5d0c8b 100644 (file)
@@ -14,6 +14,14 @@ and this project adheres to `Semantic Versioning <http://semver.org/>`__.
    :depth: 3
    :local:
 
+
+[0.5.0] - 3/18/2020
+-------------------
+::
+
+    * All xapps (via the base class) now have a logger attribute that can be invoked to provide mdc logging. It is a passthrough to the RIC mdc logger for python (untouched, no value in an API on top at the current time).
+
+
 [0.4.1] - 3/17/2020
 -------------------
 ::
index 5aef402..eac90a9 100644 (file)
@@ -28,7 +28,7 @@ ENV RMR_SEED_RT /opt/route/test_route.rt
 RUN apk update && apk add gcc musl-dev bash
 
 # Install
-RUN pip install ricxappframe==0.4.0
+RUN pip install ricxappframe==0.5.0
 COPY ping_xapp.py .
 
 # Run
index 462a717..e595d40 100644 (file)
@@ -28,7 +28,7 @@ ENV RMR_SEED_RT /opt/route/test_route.rt
 RUN apk update && apk add gcc musl-dev bash
 
 # Install
-RUN pip install ricxappframe==0.4.0
+RUN pip install ricxappframe==0.5.0
 COPY pong_xapp.py .
 
 # Run
index 145dd5b..aafebb8 100644 (file)
@@ -41,12 +41,16 @@ def entry(self):
 
         # store it in SDL and read it back; delete and read
         self.sdl_set(my_ns, "numba", number)
-        print((self.sdl_get(my_ns, "numba"), self.sdl_find_and_get(my_ns, "num")))
+        self.logger.info(self.sdl_get(my_ns, "numba"))
+        self.logger.info(self.sdl_find_and_get(my_ns, "num"))
         self.sdl_delete(my_ns, "numba")
-        print(self.sdl_get(my_ns, "numba"))
+        self.logger.info(self.sdl_get(my_ns, "numba"))
 
         # rmr receive
         for (summary, sbuf) in self.rmr_get_messages():
+            # summary is a dict that contains bytes so we can't use json.dumps on it so we have no good way to turn this into a string to use the logger unfortunately
+            # print is more "verbose" than the ric logger
+            # if you try to log this you will get: TypeError: Object of type bytes is not JSON serializable
             print(summary)
             self.rmr_free(sbuf)
 
index e0939f0..5c90685 100644 (file)
@@ -28,7 +28,8 @@ def post_init(_self):
 
 def sixtyh(self, summary, sbuf):
     """callback for 60000"""
-    print("registered 60000 handler called!")
+    self.logger.info("registered 60000 handler called!")
+    # see comment in ping about this; bytes does not work with the ric mdc logger currently
     print(summary)
     jpay = json.loads(summary["payload"])
     self.rmr_rts(sbuf, new_payload=json.dumps({"ACK": jpay["test_send"]}).encode(), new_mtype=60001, retries=100)
@@ -37,7 +38,7 @@ def sixtyh(self, summary, sbuf):
 
 def defh(self, summary, sbuf):
     """default callback"""
-    print("default handler called!")
+    self.logger.info("default handler called!")
     print(summary)
     self.rmr_free(sbuf)
 
index f278cf1..e977e27 100644 (file)
@@ -25,9 +25,6 @@ from rmr import rmr
 from mdclogpy import Logger
 
 
-mdc_logger = Logger(name=__name__)
-
-
 # Private base class; not for direct client use
 
 
@@ -57,6 +54,8 @@ class _BaseXapp:
             runs this user provided function after the base xapp is initialized
             it's signature should be post_init(self)
         """
+        # PUBLIC, can be used by xapps using self.(name):
+        self.logger = Logger(name=__name__)
 
         # Start rmr rcv thread
         self._rmr_loop = xapp_rmr.RmrLoop(port=rmr_port, wait_for_ready=rmr_wait_for_ready)
@@ -335,7 +334,7 @@ class RMRXapp(_BaseXapp):
         stops the rmr xapp completely.
         """
         super().stop()
-        mdc_logger.debug("Stopping queue reading thread..")
+        self.logger.debug("Stopping queue reading thread..")
         self._keep_going = False
 
 
index 8f57312..edbbf29 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,7 @@ def _long_descr():
 
 setup(
     name="ricxappframe",
-    version="0.4.1",
+    version="0.5.0",
     packages=find_packages(exclude=["tests.*", "tests"]),
     author="Tommy Carpenter",
     description="Xapp framework for python",
index 37aebd1..c52f54f 100644 (file)
@@ -33,7 +33,8 @@ def test_flow():
     global rmr_xapp
 
     def post_init(self):
-        print("hey")
+        self.logger.info("suppp info")
+        self.logger.debug("suppp debug")
 
     def default_handler(self, summary, sbuf):
         nonlocal def_called