Use GLib log facility instead of printf
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 12 Sep 2006 21:17:27 +0000 (21:17 +0000)
committerThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Tue, 12 Sep 2006 21:17:27 +0000 (21:17 +0000)
printf and fprintf calls were replaced by g_log calls so log level is
used and we can get to use a handler that sends to syslog later.

improxy.c

index adcaa5e..6e15f1e 100644 (file)
--- a/improxy.c
+++ b/improxy.c
@@ -9,13 +9,13 @@ void client_event (GConn* conn, GConnEvent* event, gpointer data)
   switch (event->type)
     {
     case GNET_CONN_CONNECT:
-      fprintf (stderr, "Connected to localhost:80.\n");
+      g_debug ("Connected to localhost:80.");
       gnet_conn_read (conn);
       break;
     case GNET_CONN_READ:
       if (server == NULL)
        {
-         fprintf (stderr, "Establishing connection to localhost:80.\n");
+         g_debug ("Establishing connection to localhost:80.");
          server = gnet_conn_new ("127.0.0.1", 80, client_event, (gpointer) conn);
          gnet_conn_connect (server);
          gnet_conn_set_callback (conn, client_event, (gpointer) server);
@@ -30,7 +30,7 @@ void client_event (GConn* conn, GConnEvent* event, gpointer data)
       gnet_conn_unref (conn);
       break;
     default:
-      fprintf (stderr, "Received an unexpected client event.\n");
+      g_warning ("Received an unexpected client event.");
       break;
     }
 }
@@ -39,9 +39,10 @@ void new_client (GServer* server, GConn* conn, gpointer data)
 {
   if (conn == NULL)
     {
-      fprintf (stderr, "Server has received an error event.\n");
+      g_critical ("Server has received an error event.");
       return;
     }
+  g_message ("Received connection from %s.", conn->hostname);
   gnet_conn_set_callback (conn, client_event, NULL);
   gnet_conn_read (conn);
 }
@@ -63,7 +64,7 @@ int main ()
   conf_address = g_key_file_get_string (keyfile, "global", "address", NULL);
   port = g_key_file_get_integer (keyfile, "global", "port", NULL);
 
-  printf ("Listen address is %s:%d\n", conf_address, port);
+  g_message ("Listen address is %s:%d.", conf_address, port);
 
   inetaddr = gnet_inetaddr_new_nonblock (conf_address, port);
   gnet_server_new (inetaddr, port, new_client, NULL);