dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/41812?usp=email )
Change subject: transport/init: use PySimLogger to print messages ......................................................................
transport/init: use PySimLogger to print messages
The module still uses print to output information. Let's replace those print calls with the more modern PySimLogger method calls.
Change-Id: I2e2ec2b84f3b84dbd8a029ae9bb64b7a96ddbde3 --- M pySim/transport/__init__.py 1 file changed, 11 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/12/41812/1
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index f82f4df..39c9886 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -29,6 +29,9 @@ from pySim.exceptions import * from pySim.utils import SwHexstr, SwMatchstr, ResTuple, sw_match, parse_command_apdu from pySim.cat import ProactiveCommand, CommandDetails, DeviceIdentities, Result +from pySim.log import PySimLogger + +log = PySimLogger.get("TRANSPORT")
class ApduTracer: def trace_command(self, cmd): @@ -43,11 +46,11 @@ class StdoutApduTracer(ApduTracer): """Minimalistic APDU tracer, printing commands to stdout.""" def trace_response(self, cmd, sw, resp): - print("-> %s %s" % (cmd[:10], cmd[10:])) - print("<- %s: %s" % (sw, resp)) + log.info("-> %s %s" % (cmd[:10], cmd[10:])) + log.info("<- %s: %s" % (sw, resp))
def trace_reset(self): - print("-- RESET") + log.info("-- RESET")
class ProactiveHandler(abc.ABC): """Abstract base class representing the interface of some code that handles @@ -174,7 +177,7 @@ if self.apdu_strict: raise ValueError(exeption_str) else: - print('Warning: %s' % exeption_str) + log.warning(exeption_str)
return (data, sw)
@@ -208,7 +211,7 @@ # parse the proactive command pcmd = ProactiveCommand() parsed = pcmd.from_tlv(h2b(fetch_rv[0])) - print("FETCH: %s (%s)" % (fetch_rv[0], type(parsed).__name__)) + log.info("FETCH: %s (%s)" % (fetch_rv[0], type(parsed).__name__)) if self.proactive_handler: # Extension point: If this does return a list of TLV objects, # they could be appended after the Result; if the first is a @@ -358,13 +361,13 @@ from pySim.transport.modem_atcmd import ModemATCommandLink sl = ModemATCommandLink(opts, **kwargs) else: # Serial reader is default - print("No reader/driver specified; falling back to default (Serial reader)") + log.warning("No reader/driver specified; falling back to default (Serial reader)") from pySim.transport.serial import SerialSimLink sl = SerialSimLink(opts, **kwargs)
if os.environ.get('PYSIM_INTEGRATION_TEST') == "1": - print("Using %s reader interface" % (sl.name)) + log.info("Using %s reader interface" % (sl.name)) else: - print("Using reader %s" % sl) + log.info("Using reader %s" % sl)
return sl