laforge has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-remsim/+/17363 )

Change subject: user_simtrace2: Stop using printf, use libosmocore logging
......................................................................

user_simtrace2: Stop using printf, use libosmocore logging

This way we have consistent logging from all parts of the code via
the common libosmocore logging infrastructure.

Change-Id: I9ace31d781dd3e50f9a5d9239bafa87a01abb0d6
---
M src/client/user_simtrace2.c
M src/debug.c
M src/debug.h
3 files changed, 24 insertions(+), 18 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/src/client/user_simtrace2.c b/src/client/user_simtrace2.c
index 24a8d09..5d5bfc1 100644
--- a/src/client/user_simtrace2.c
+++ b/src/client/user_simtrace2.c
@@ -37,6 +37,8 @@
 #include "client.h"
 #include "debug.h"

+#define LOGCI(ci, lvl, fmt, args ...) \
+       LOGP(DST2, lvl, fmt, ## args)

 /***********************************************************************
  * Incoming Messages from cardem firmware
@@ -48,9 +50,8 @@
        struct cardemu_usb_msg_status *status;
        status = (struct cardemu_usb_msg_status *) buf;

-       printf("SIMtrace => STATUS: flags=0x%x, fi=%u, di=%u, wi=%u wtime=%u\n",
-               status->flags, status->fi, status->di, status->wi,
-               status->waiting_time);
+       LOGCI(ci, LOGL_INFO, "SIMtrace => STATUS: flags=0x%x, fi=%u, di=%u, 
wi=%u wtime=%u\n",
+               status->flags, status->fi, status->di, status->wi, 
status->waiting_time);

        return 0;
 }
@@ -65,7 +66,7 @@
                .len = sizeof(pts->req),
        };

-       printf("SIMtrace => PTS req: %s\n", osmo_hexdump(pts->req, 
sizeof(pts->req)));
+       LOGCI(ci, LOGL_INFO, "SIMtrace => PTS req: %s\n", 
osmo_hexdump(pts->req, sizeof(pts->req)));

        osmo_fsm_inst_dispatch(bc->main_fi, MF_E_MDM_PTS_IND, &fpts);

@@ -78,9 +79,8 @@
        struct cardemu_usb_msg_error *err;
        err = (struct cardemu_usb_msg_error *) buf;

-       printf("SIMtrace => ERROR: %u/%u/%u: %s\n",
-               err->severity, err->subsystem, err->code,
-               err->msg_len ? (char *)err->msg : "");
+       LOGCI(ci, LOGL_ERROR, "SIMtrace => ERROR: %u/%u/%u: %s\n",
+               err->severity, err->subsystem, err->code, err->msg_len ? (char 
*)err->msg : "");

        return 0;
 }
@@ -95,7 +95,7 @@
        struct frontend_tpdu ftpdu;
        int rc;

-       printf("SIMtrace => DATA: flags=%x, %s: ", data->flags,
+       LOGCI(ci, LOGL_DEBUG, "SIMtrace => DATA: flags=%x, %s: ", data->flags,
                osmo_hexdump(data->data, data->data_len));

        /* parse the APDU data in the USB message */
@@ -131,7 +131,7 @@
        struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *)buf;
        int rc;

-       printf("SIMtrace -> %s\n", osmo_hexdump(buf, len));
+       LOGCI(ci, LOGL_DEBUG, "SIMtrace -> %s\n", osmo_hexdump(buf, len));

        buf += sizeof(*sh);

@@ -149,7 +149,7 @@
                /* firmware confirms configuration change; ignore */
                break;
        default:
-               printf("unknown simtrace msg type 0x%02x\n", sh->msg_type);
+               LOGCI(ci, LOGL_ERROR, "unknown simtrace msg type 0x%02x\n", 
sh->msg_type);
                rc = -1;
                break;
        }
@@ -177,7 +177,7 @@
                .waiting_time = status->waiting_time,
        };

-       printf("SIMtrace IRQ STATUS: flags=0x%x, fi=%u, di=%u, wi=%u 
wtime=%u\n",
+       LOGCI(ci, LOGL_INFO, "SIMtrace IRQ STATUS: flags=0x%x, fi=%u, di=%u, 
wi=%u wtime=%u\n",
                status->flags, status->fi, status->di, status->wi,
                status->waiting_time);

@@ -190,7 +190,7 @@
        struct simtrace_msg_hdr *sh = (struct simtrace_msg_hdr *)buf;
        int rc;

-       printf("SIMtrace IRQ %s\n", osmo_hexdump(buf, len));
+       LOGCI(ci, LOGL_INFO, "SIMtrace IRQ %s\n", osmo_hexdump(buf, len));

        buf += sizeof(*sh);

@@ -199,7 +199,7 @@
                rc = process_irq_status(ci, buf, len);
                break;
        default:
-               printf("unknown simtrace msg type 0x%02x\n", sh->msg_type);
+               LOGCI(ci, LOGL_ERROR, "unknown simtrace msg type 0x%02x\n", 
sh->msg_type);
                rc = -1;
                break;
        }
@@ -218,11 +218,11 @@
                process_usb_msg(ci, xfer->buffer, xfer->actual_length);
                break;
        case LIBUSB_TRANSFER_NO_DEVICE:
-               fprintf(stderr, "USB device disappeared\n");
+               LOGCI(ci, LOGL_FATAL, "USB device disappeared\n");
                exit(1);
                break;
        default:
-               fprintf(stderr, "USB IN transfer failed, status=%u\n", 
xfer->status);
+               LOGCI(ci, LOGL_FATAL, "USB IN transfer failed, status=%u\n", 
xfer->status);
                exit(1);
                break;
        }
@@ -269,11 +269,11 @@
                process_usb_msg_irq(ci, xfer->buffer, xfer->actual_length);
                break;
        case LIBUSB_TRANSFER_NO_DEVICE:
-               fprintf(stderr, "USB device disappeared\n");
+               LOGCI(ci, LOGL_FATAL, "USB device disappeared\n");
                exit(1);
                break;
        default:
-               fprintf(stderr, "USB IRQ transfer failed, status=%u\n", 
xfer->status);
+               LOGCI(ci, LOGL_FATAL, "USB IN transfer failed, status=%u\n", 
xfer->status);
                exit(1);
                break;
        }
@@ -341,7 +341,7 @@
        ac.sw[0] = data[len-2];
        ac.sw[1] = data[len=1];

-       printf("SIMtrace <= SW=0x%02x%02x, len_rx=%zu\n", ac.sw[0], ac.sw[1], 
len-2);
+       LOGCI(ci, LOGL_DEBUG, "SIMtrace <= SW=0x%02x%02x, len_rx=%zu\n", 
ac.sw[0], ac.sw[1], len-2);
        if (len > 2) { // send PB and data to modem
                osmo_st2_cardem_request_pb_and_tx(ci, ac.hdr.ins, data, len-2);
        }
diff --git a/src/debug.c b/src/debug.c
index 70c04d2..91c2f71 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -31,6 +31,11 @@
                .loglevel = LOGL_DEBUG,
                .enabled = 1,
        },
+       [DST2] = {
+               .name = "DST2",
+               .loglevel = LOGL_INFO,
+               .enabled = 1,
+       },
 };

 const struct log_info log_info = {
diff --git a/src/debug.h b/src/debug.h
index e3994b4..2a3e5a3 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -3,6 +3,7 @@

 enum {
        DMAIN,
+       DST2,
 };

 extern const struct log_info log_info;

--
To view, visit https://gerrit.osmocom.org/c/osmo-remsim/+/17363
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-Change-Id: I9ace31d781dd3e50f9a5d9239bafa87a01abb0d6
Gerrit-Change-Number: 17363
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-MessageType: merged

Reply via email to