From: Tommy Carpenter Date: Wed, 18 Mar 2020 14:34:28 +0000 (-0400) Subject: Xapps now have an accessible mdc logger. X-Git-Tag: 0.5.0~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=0f8305b167601ce6ca87c55208038455a65eab62;p=ric-plt%2Fxapp-frame-py.git Xapps now have an accessible mdc logger. Issue-ID: RIC-228 Change-Id: Ic1a4a6931398535821db238ed0e67c8181c163bd Signed-off-by: Tommy Carpenter --- diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 8491cf4..a5d0c8b 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -14,6 +14,14 @@ and this project adheres to `Semantic Versioning `__. :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 ------------------- :: diff --git a/examples/Dockerfile-Ping b/examples/Dockerfile-Ping index 5aef402..eac90a9 100644 --- a/examples/Dockerfile-Ping +++ b/examples/Dockerfile-Ping @@ -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 diff --git a/examples/Dockerfile-Pong b/examples/Dockerfile-Pong index 462a717..e595d40 100644 --- a/examples/Dockerfile-Pong +++ b/examples/Dockerfile-Pong @@ -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 diff --git a/examples/ping_xapp.py b/examples/ping_xapp.py index 145dd5b..aafebb8 100644 --- a/examples/ping_xapp.py +++ b/examples/ping_xapp.py @@ -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) diff --git a/examples/pong_xapp.py b/examples/pong_xapp.py index e0939f0..5c90685 100644 --- a/examples/pong_xapp.py +++ b/examples/pong_xapp.py @@ -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) diff --git a/ricxappframe/xapp_frame.py b/ricxappframe/xapp_frame.py index f278cf1..e977e27 100644 --- a/ricxappframe/xapp_frame.py +++ b/ricxappframe/xapp_frame.py @@ -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 diff --git a/setup.py b/setup.py index 8f57312..edbbf29 100644 --- 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", diff --git a/tests/test_xapps.py b/tests/test_xapps.py index 37aebd1..c52f54f 100644 --- a/tests/test_xapps.py +++ b/tests/test_xapps.py @@ -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