[Spice-devel] [spice-gtk v3 15/19] log: use spice logging instead of (f)printf
Victor Toso
victortoso at redhat.com
Sat Mar 12 14:32:16 UTC 2016
---
src/channel-cursor.c | 16 +++++++----
src/coroutine_gthread.c | 4 +--
src/coroutine_ucontext.c | 2 +-
src/coroutine_winfibers.c | 2 +-
src/spice-channel.c | 50 ++++++++++++++++++++--------------
src/spice-client-glib-usb-acl-helper.c | 6 ++--
6 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/src/channel-cursor.c b/src/channel-cursor.c
index 2dbdc90..16ac7b4 100644
--- a/src/channel-cursor.c
+++ b/src/channel-cursor.c
@@ -208,27 +208,31 @@ static void print_cursor(display_cursor *cursor, const guint8 *data)
{
int x, y, bpl;
const guint8 *xor, *and;
+ GString *gstr = g_string_sized_new();
bpl = (cursor->hdr.width + 7) / 8;
and = data;
xor = and + bpl * cursor->hdr.height;
- printf("data (%d x %d):\n", cursor->hdr.width, cursor->hdr.height);
+ spice_debug("data (%d x %d):", cursor->hdr.width, cursor->hdr.height);
for (y = 0 ; y < cursor->hdr.height; ++y) {
for (x = 0 ; x < cursor->hdr.width / 8; x++) {
- printf("%02X", and[x]);
+ g_string_append_printf(gstr, "%02X", and[x]);
}
and += bpl;
- printf("\n");
+ spice_debug("%s", gstr->str);
+ gstr = g_string_set_size(gstr, 0);
}
- printf("xor:\n");
+ spice_debug("xor:");
for (y = 0 ; y < cursor->hdr.height; ++y) {
for (x = 0 ; x < cursor->hdr.width / 8; ++x) {
- printf("%02X", xor[x]);
+ g_string_append_printf(gstr, "%02X", xor[x]);
}
xor += bpl;
- printf("\n");
+ spice_debug("%s", gstr->str);
+ gstr = g_string_set_size(gstr, 0);
}
+ g_string_free(gstr, TRUE);
}
#endif
diff --git a/src/coroutine_gthread.c b/src/coroutine_gthread.c
index b0098fa..080a3f2 100644
--- a/src/coroutine_gthread.c
+++ b/src/coroutine_gthread.c
@@ -30,7 +30,7 @@ static struct coroutine *current;
static struct coroutine leader;
#if 0
-#define CO_DEBUG(OP) fprintf(stderr, "%s %p %s %d\n", OP, g_thread_self(), __FUNCTION__, __LINE__)
+#define CO_DEBUG(OP) spice_debug("%s %p", OP, g_thread_self())
#else
#define CO_DEBUG(OP)
#endif
@@ -155,7 +155,7 @@ void *coroutine_yield(void *arg)
{
struct coroutine *to = coroutine_self()->caller;
if (!to) {
- fprintf(stderr, "Co-routine is yielding to no one\n");
+ spice_warning("Co-routine is yielding to no one");
abort();
}
diff --git a/src/coroutine_ucontext.c b/src/coroutine_ucontext.c
index d709a33..04d35f2 100644
--- a/src/coroutine_ucontext.c
+++ b/src/coroutine_ucontext.c
@@ -130,7 +130,7 @@ void *coroutine_yield(void *arg)
{
struct coroutine *to = coroutine_self()->caller;
if (!to) {
- fprintf(stderr, "Co-routine is yielding to no one\n");
+ spice_warning("Co-routine is yielding to no one");
abort();
}
coroutine_self()->caller = NULL;
diff --git a/src/coroutine_winfibers.c b/src/coroutine_winfibers.c
index a56d33d..6ef2a08 100644
--- a/src/coroutine_winfibers.c
+++ b/src/coroutine_winfibers.c
@@ -106,7 +106,7 @@ void *coroutine_yield(void *arg)
{
struct coroutine *to = coroutine_self()->caller;
if (!to) {
- fprintf(stderr, "Co-routine is yielding to no one\n");
+ spice_warning("Co-routine is yielding to no one");
abort();
}
coroutine_self()->caller = NULL;
diff --git a/src/spice-channel.c b/src/spice-channel.c
index 6225831..55c97de 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -551,18 +551,27 @@ void *spice_msg_in_raw(SpiceMsgIn *in, int *len)
static void hexdump(const char *prefix, unsigned char *data, int len)
{
int i;
+ GString *gstr;
+ /* Create a GString big enough for each hexdump line */
+ gstr = g_string_sized_new(40);
for (i = 0; i < len; i++) {
- if (i % 16 == 0)
- fprintf(stderr, "%s:", prefix);
- if (i % 4 == 0)
- fprintf(stderr, " ");
- fprintf(stderr, " %02x", data[i]);
- if (i % 16 == 15)
- fprintf(stderr, "\n");
+ if (i % 4 == 0) {
+ gstr = g_string_append(gstr, " ");
+ }
+
+ g_string_append_printf(gstr, " %02x", data[i]);
+
+ if (i % 16 == 15) {
+ spice_debug("%s:%s", prefix, gstr->str);
+ gstr = g_string_set_size(gstr, 0);
+ }
+ }
+
+ if (i % 16 != 0) {
+ spice_debug("%s:%s", prefix, gstr->str);
}
- if (i % 16 != 0)
- fprintf(stderr, "\n");
+ g_string_free(gstr, TRUE);
}
G_GNUC_INTERNAL
@@ -570,11 +579,12 @@ void spice_msg_in_hexdump(SpiceMsgIn *in)
{
SpiceChannelPrivate *c = in->channel->priv;
- fprintf(stderr, "--\n<< hdr: %s serial %" PRIu64 " type %d size %d sub-list %d\n",
- c->name, spice_header_get_in_msg_serial(in),
- spice_header_get_msg_type(in->header, c->use_mini_header),
- spice_header_get_msg_size(in->header, c->use_mini_header),
- spice_header_get_msg_sub_list(in->header, c->use_mini_header));
+ spice_debug("<< hdr: %s serial %" PRIu64 " type %d size %d sub-list %d",
+ c->name,
+ spice_header_get_in_msg_serial(in),
+ spice_header_get_msg_type(in->header, c->use_mini_header),
+ spice_header_get_msg_size(in->header, c->use_mini_header),
+ spice_header_get_msg_sub_list(in->header, c->use_mini_header));
hexdump("<< msg", in->data, in->dpos);
}
@@ -583,12 +593,12 @@ void spice_msg_out_hexdump(SpiceMsgOut *out, unsigned char *data, int len)
{
SpiceChannelPrivate *c = out->channel->priv;
- fprintf(stderr, "--\n>> hdr: %s serial %" PRIu64 " type %d size %d sub-list %d\n",
- c->name,
- spice_header_get_out_msg_serial(out),
- spice_header_get_msg_type(out->header, c->use_mini_header),
- spice_header_get_msg_size(out->header, c->use_mini_header),
- spice_header_get_msg_sub_list(out->header, c->use_mini_header));
+ spice_debug(">> hdr: %s serial %" PRIu64 " type %d size %d sub-list %d",
+ c->name,
+ spice_header_get_out_msg_serial(out),
+ spice_header_get_msg_type(out->header, c->use_mini_header),
+ spice_header_get_msg_size(out->header, c->use_mini_header),
+ spice_header_get_msg_sub_list(out->header, c->use_mini_header));
hexdump(">> msg", data, len);
}
diff --git a/src/spice-client-glib-usb-acl-helper.c b/src/spice-client-glib-usb-acl-helper.c
index 3c5de05..cd40b3f 100644
--- a/src/spice-client-glib-usb-acl-helper.c
+++ b/src/spice-client-glib-usb-acl-helper.c
@@ -40,15 +40,15 @@
do { \
/* We print the error both to stdout, for the app invoking us and \
stderr for the end user */ \
- fprintf(stdout, "Error " __VA_ARGS__); \
- fprintf(stderr, "spice-client-glib-usb-helper: Error " __VA_ARGS__); \
+ spice_warning("Error " __VA_ARGS__); \
+ spice_printerr("spice-client-glib-usb-helper: Error " __VA_ARGS__); \
exit_status = 1; \
cleanup(); \
} while (0)
#define ERROR(...) \
do { \
- fprintf(stdout, __VA_ARGS__); \
+ spice_warning(__VA_ARGS__); \
cleanup(); \
} while (0)
--
2.5.0
More information about the Spice-devel
mailing list