Change in mncc-python[master]: *.py: use generic logging framework instead of print()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Sep 30 12:30:40 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11161 )

Change subject: *.py: use generic logging framework instead of print()
......................................................................

*.py: use generic logging framework instead of print()

Change-Id: I025ddae64e41319abac8e2cd2e266db83aea4a7b
---
M contrib/manual_test_server.py
M gsm_call_fsm.py
M mncc_sock.py
M mncc_test.py
M smpp_test.py
5 files changed, 28 insertions(+), 24 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved; Verified



diff --git a/contrib/manual_test_server.py b/contrib/manual_test_server.py
index 7338129..4b2b5bd 100644
--- a/contrib/manual_test_server.py
+++ b/contrib/manual_test_server.py
@@ -91,39 +91,39 @@
 # Say hello and set-up a call
 conn.send_msg(MnccMessageBuilder.build_hello())
 conn.send_msg(MnccMessageBuilder.build_setup_ind("1234", "5000"))
-print("=> Sent hello + setup indication")
+log.info("=> Sent hello + setup indication")
 
 # Wait for the RTP crate.. and actknowledge it..
 msg = conn.recv()
 assert msg.msg_type == mncc.MNCC_RTP_CREATE
-print("<= Received request to create a RTP socket")
+log.info("<= Received request to create a RTP socket")
 conn.send_msg(MnccMessageBuilder.build_rtp_msg(mncc.MNCC_RTP_CREATE,
                                                 msg.callref,
                                                 #socket.INADDR_LOOPBACK, 4000))
                                                 socket.INADDR_ANY, 4000))
-print("=> Claimed socket was created...")
+log.info("=> Claimed socket was created...")
 
 msg = conn.recv()
 assert msg.msg_type == mncc.MNCC_CALL_PROC_REQ
-print("<= Received proceeding...")
+log.info("<= Received proceeding...")
 
 
 
 while True:
     msg = conn.recv()
     if msg.msg_type == mncc.MNCC_ALERT_REQ:
-        print("=> I should alert...")
+        log.info("=> I should alert...")
         continue
     if msg.msg_type == mncc.MNCC_RTP_CONNECT:
         conn.send_msg(MnccMessageBuilder.build_rtp_msg(mncc.MNCC_RTP_CONNECT,
                                                 msg.callref,
                                                 socket.INADDR_LOOPBACK, 4000))
-        print("=> I needed to connect RTP...")
+        log.info("=> I needed to connect RTP...")
         continue
     if msg.msg_type == mncc.MNCC_SETUP_RSP:
-        print("=> Call is connected?")
+        log.info("=> Call is connected?")
         conn.send_msg(MnccMessageBuilder.build_setup_cmpl_ind(msg.callref))
         send_dtmf(msg.callref)
         continue
 
-    print(msg)
+    log.debug(msg)
diff --git a/gsm_call_fsm.py b/gsm_call_fsm.py
index c62df0c..a9ad8c0 100644
--- a/gsm_call_fsm.py
+++ b/gsm_call_fsm.py
@@ -13,6 +13,8 @@
 import ctypes
 import pykka
 
+import logging as log
+
 from fysom import Fysom
 from mncc_sock import mncc_msg, mncc_number, mncc_rtp_msg, mncc_bridge_msg, mncc_bearer_cap
 
@@ -76,7 +78,7 @@
         return GsmCallFsm.last_callref;
 
     def _printstatechange(self, e):
-        print '%s: event: %s, %s -> %s' % (self, e.event, e.src, e.dst)
+        log.debug('%s: event: %s, %s -> %s' % (self, e.event, e.src, e.dst))
         if self.ctrl_ref != None:
             self.ctrl_ref.tell({'type':'call_state_change', 'called':self.called, 'old_state':e.src, 'new_state':e.dst})
 
@@ -98,7 +100,7 @@
     def _onmncc_call_conf_ind(self, e):
         msg_in = e.args[0]
         codec = self.find_matching_codec(msg_in.bearer_cap.speech_ver)
-        print '%s: CALL-CONF.ind(selected codec = %s)' % (self, codec)
+        log.info('%s: CALL-CONF.ind(selected codec = %s)' % (self, codec))
         # select the according lchan_mode
         lchan_mode = codec.to_lchan_mode()
         msg = mncc_msg(msg_type = mncc.MNCC_LCHAN_MODIFY, callref = msg_in.callref, lchan_mode = lchan_mode)
@@ -292,7 +294,7 @@
         if message['type'] == 'mncc':
             msg = message['msg']
             if msg.callref == self.callref:
-                print '%s: on_receive(mncc, %s)' % (self, msg)
+                log.debug('%s: on_receive(mncc, %s)' % (self, msg))
                 return self._handle_mncc(msg)
         elif message['type'] == 'start_mt_call':
             self.start_mt_call(message['calling'], message['called'])
@@ -326,7 +328,7 @@
         self.call_b.tell({'type':'start_mt_call', 'calling':self.msisdn_a, 'called':self.msisdn_b})
 
     def rtp_created(self, msisdn, rtp):
-        print 'CallConnector:rtp_created(%s) %s' % (msisdn, rtp)
+        log.info('CallConnector:rtp_created(%s) %s' % (msisdn, rtp))
         if self.rtp_bridge == False:
             raise Exception('GsmCallConnector', 'rtp_created but not in RTP bridge mode')
         if msisdn == self.msisdn_a:     # A->B leg
@@ -345,7 +347,8 @@
         self.mncc_act.tell({'type': 'send', 'msg': msg})
 
     def call_state_change(self, msisdn, old_state, new_state):
-        print 'CallConnector:leg_state_change(%s) %s -> %s' % (msisdn, old_state, new_state)
+        log.debug('CallConnector:leg_state_change(%s) %s -> %s'
+            % (msisdn, old_state, new_state))
         if msisdn == self.msisdn_a:     # A->B leg
             self.state_a = new_state
         elif msisdn == self.msisdn_b:   # B->A leg
@@ -353,7 +356,7 @@
         if self.rtp_bridge == False and self.state_a == 'ACTIVE' and self.state_b == 'ACTIVE':
             self.bridge_legs()
         if self.state_a == 'NULL' and self.state_b == 'NULL':
-            print 'Both A and B in state NULL -> Terminating'
+            log.info('Both A and B in state NULL -> Terminating')
             self.stop()
 
     def on_receive(self, message):
diff --git a/mncc_sock.py b/mncc_sock.py
index 0a64a81..009a476 100644
--- a/mncc_sock.py
+++ b/mncc_sock.py
@@ -9,6 +9,7 @@
 # Licensed under GNU General Public License, Version 2 or at your
 # option, any later version.
 
+import logging as log
 import socket
 import os
 import mncc
@@ -120,14 +121,14 @@
     def __init__(self, address = '/tmp/bsc_mncc'):
         super(MnccSocketBase, self).__init__()
         self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
-        print('connecting to %s' % address)
+        log.info('Connecting to %s' % address)
         self.sock.connect(address)
 
         # Check the HELLO message
         self.check_hello()
 
     def check_hello(self):
-        print('Waiting for HELLO message...')
+        log.debug('Waiting for HELLO message...')
         msg = self.recv()
 
         # Match expected message type
@@ -149,7 +150,7 @@
             msg.lchan_type_offset != mncc.gsm_mncc.lchan_type.offset):
                 raise AssertionError('MNCC message alignment mismatch\n')
 
-        print('Received %s' % msg)
+        log.info('Received %s' % msg)
 
 class MnccSocketServer(object):
     def __init__(self, address = '/tmp/bsc_mncc'):
diff --git a/mncc_test.py b/mncc_test.py
index 9222605..508c5be 100755
--- a/mncc_test.py
+++ b/mncc_test.py
@@ -13,7 +13,7 @@
 from mncc_sock import MnccSocket
 from thread import start_new_thread
 import pykka
-import logging
+import logging as log
 import signal, sys, time
 import readline, code
 
@@ -26,7 +26,7 @@
     def on_receive(self, message):
         if message['type'] == 'send':
             msg = message['msg']
-            print 'MnccActor TxMNCC %s' % msg
+            log.debug('MnccActor TxMNCC %s' % msg)
             mncc_sock.send(msg)
         else:
             raise Exception('mncc', 'MnccActor Received unhandled %s' % message)
@@ -36,10 +36,10 @@
     while 1:
         msg = mncc_sock.recv()
         if msg.is_frame():
-            print("Dropping traffic frame: %s" % msg)
+            log.warning("Dropping traffic frame: %s" % msg)
             continue
 
-        print "MnccActor RxMNCC %s, broadcasting to Call FSMs" % msg
+        log.debug("MnccActor RxMNCC %s, broadcasting to Call FSMs" % msg)
         # we simply broadcast to all calls
         pykka.ActorRegistry.broadcast({'type': 'mncc', 'msg': msg}, GsmCallFsm)
 
@@ -48,7 +48,7 @@
     pykka.ActorRegistry.stop_all()
     sys.exit(0)
 
-logging.basicConfig(level = logging.DEBUG,
+log.basicConfig(level = log.DEBUG,
     format = "%(levelname)s %(filename)s:%(lineno)d %(message)s")
 
 signal.signal(signal.SIGINT, sigint_handler)
diff --git a/smpp_test.py b/smpp_test.py
index ad7d4dc..71eba91 100755
--- a/smpp_test.py
+++ b/smpp_test.py
@@ -17,7 +17,7 @@
 def send_message(dest, string):
     parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string)
 
-    print 'Sending SMS "%s" to %s' % (string, dest)
+    log.info('Sending SMS "%s" to %s' % (string, dest))
     for part in parts:
         pdu = client.send_message(
             source_addr_ton=smpplib.consts.SMPP_TON_INTL,
@@ -32,7 +32,7 @@
             esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
             registered_delivery=False,
     )
-    print(pdu.sequence)
+    log.debug(pdu.sequence)
 
 
 client = smpplib.client.Client('127.0.0.1', 2775)

-- 
To view, visit https://gerrit.osmocom.org/11161
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I025ddae64e41319abac8e2cd2e266db83aea4a7b
Gerrit-Change-Number: 11161
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180930/8d4b8d5b/attachment.htm>


More information about the gerrit-log mailing list