--- orig/src/networks/bittorrent/bTClients.ml
+++ mod/src/networks/bittorrent/bTClients.ml
@@ -89,7 +89,7 @@
   match file.file_swarmer with
     None -> ()
   | Some swarmer ->
-      lprintf "Connect tracker.........\n";
+      BLOG DEBUG : "Connecting tracker.........\n" ELOG;
       let downloaded = Int64Swarmer.downloaded swarmer in
       let args,must_check_delay, downloaded = 
         match event with
@@ -121,7 +121,7 @@
             Printf.sprintf "MLdonkey %s" Autoconf.current_version;
           } in
         
-        lprintf "Request sent to tracker\n";
+        BLOG DEBUG : "Request sent to tracker\n" ELOG;
         H.wget r 
           (fun fileres -> 
             file.file_tracker_last_conn <- last_time ();
@@ -185,8 +185,10 @@
   @param reason The reason for the disconnection (see in BasicSocket.ml)
 *)  
 let disconnect_client c reason =
-  if !verbose_msg_clients then
-    lprintf "CLIENT %d: disconnected: %s\n" (client_num c) (string_of_reason reason);
+  BLOG DEBUG (!verbose_msg_clients) : 
+    "CLIENT %d: disconnected: %s\n" (client_num c) 
+    (string_of_reason reason) 
+  ELOG;
   begin
     match c.client_sock with
       NoConnection -> ()
@@ -259,8 +261,8 @@
   Hashtbl.iter (fun _ c ->
   if not ( !must_keep && (client_has_a_slot (as_client c) || c.client_interested)) then	
     begin
-      if !verbose_msg_clients then
-        lprintf "disconnect since download is finished\n";
+      BLOG DEBUG (!verbose_msg_clients) :
+        "disconnect since download is finished\n" ELOG;
       disconnect_client c Closed_by_user
     end
   ) file.file_clients
@@ -295,9 +297,9 @@
       for i = 0 to String.length bitmap - 1 do
         if bitmap.[i] <> '3' then raise Not_found;
       done;  
-      if (file_size file <> Int64Swarmer.downloaded swarmer)
-      then
-        lprintf "Downloaded size differs after complete verification\n";
+        BLOG WARN (file_size file <> Int64Swarmer.downloaded swarmer) : 
+	  "%s : Downloaded size differs after complete verification\n" (file.file_name) 
+	ELOG;
       download_finished file
       
     
@@ -335,9 +337,9 @@
     None -> assert false
   | Some swarmer ->
       let bitmap = Int64Swarmer.verified_bitmap swarmer in
-      if !verbose then begin
-      lprintf "Verified bitmap: [%s]\n" bitmap;
-      end;
+	BLOG DEBUG (!verbose) : 
+	  "Verified bitmap: [%s]\n" bitmap
+	ELOG;      
       send_client c (BitField 
       (        
       let nchunks = String.length bitmap in
@@ -380,60 +382,70 @@
     (proto, file_id, peer_id) = 
   try
     set_lifetime sock 600.;
-    if !verbose_msg_clients then
-      lprintf "client_parse_header %d\n" counter;
+    BLOG DEBUG (!verbose_msg_clients) : 
+      "client_parse_header %d\n" counter
+    ELOG;
     
     let file = Hashtbl.find files_by_uid file_id in
-    if !verbose_msg_clients then
-      lprintf "file found\n";
+      BLOG DEBUG  (!verbose_msg_clients) : 
+	"file found\n"
+      ELOG;
     let c = 
       match !cc with 
         None ->
           let c = new_client file peer_id (TcpBufferedSocket.host sock) in
-          lprintf "CLIENT %d: incoming CONNECTION\n" (client_num c);
+          BLOG DEBUG : "CLIENT %d: incoming CONNECTION\n" (client_num c) ELOG;
           cc := Some c;
           c
       | Some c ->
           if c.client_uid <> peer_id then begin
-              lprintf "Unexpected client by UID\n";
+              BLOG DEBUG : 
+		"Unexpected client by UID\n" 
+	      ELOG;
               let ccc = new_client file peer_id (TcpBufferedSocket.host sock) in
-              lprintf "CLIENT %d: testing instead of %d\n"
-                (client_num ccc) (client_num c);
+		BLOG DEBUG : 
+		  "CLIENT %d: testing instead of %d\n" 
+                  (client_num ccc) (client_num c) 
+		ELOG;
               (match ccc.client_sock with 
                   Connection _ -> 
-                    lprintf "This client is already connected\n";
+                    BLOG DEBUG :
+		    "This client is already connected\n" 
+		    ELOG;
                     close sock (Closed_for_error "Already connected"); 
                     remove_client ccc;
                     c
                 | _ -> 
-                    lprintf "CLIENT %d: recovered by UID\n" (client_num ccc);
+                    BLOG DEBUG :
+		    "CLIENT %d: recovered by UID\n" (client_num ccc)
+		    ELOG;
                     remove_client c;
                     cc := Some ccc;
                     ccc)
             end else
             c          
     in
-    
-    if !verbose_msg_clients then begin
-        let (ip,port) = c.client_host in
-        lprintf "CLIENT %d: Connected (%s:%d)\n"  (client_num c)
-        (Ip.to_string ip) port
-        ;
-      end;
+    BLOG DEBUG (!verbose_msg_clients) :       
+      "CLIENT %d: Connected (%s:%d)\n"  (client_num c)
+      (Ip.to_string (fst c.client_host)) (snd c.client_host)
+    ELOG;
     
     (match c.client_sock with
         NoConnection ->
-          if !verbose_msg_clients then
-            lprintf "Client was not connected !!!\n";
+	  BLOG DEBUG (!verbose_msg_clients) : 
+            "Client was not connected !!!\n"
+	  ELOG;
           c.client_sock <- Connection sock
       | ConnectionWaiting token ->
           cancel_token token;
-          if !verbose_msg_clients then
-            lprintf "Client was not connected !!!\n";
+	  BLOG DEBUG (!verbose_msg_clients) : 
+            "Client was not connected !!!\n"
+	  ELOG;
           c.client_sock <- Connection sock
       | Connection s when s != sock -> 
-          if !verbose_msg_clients then 
-            lprintf "CLIENT %d: IMMEDIATE RECONNECTION\n" (client_num c);
+	  BLOG DEBUG (!verbose_msg_clients) : 
+            "CLIENT %d: IMMEDIATE RECONNECTION\n" (client_num c)
+	  ELOG;
           disconnect_client c (Closed_for_error "Reconnected");
           c.client_sock <- Connection sock;
       | Connection _  -> ()
@@ -446,8 +458,9 @@
         send_init !!client_uid file_id sock;
       end;
     connection_ok c.client_connection_control;
-    if !verbose_msg_clients then
-      lprintf "file and client found\n";
+    BLOG DEBUG (!verbose_msg_clients) : 
+      "file and client found\n"
+    ELOG;
 (*    if not c.client_incoming then *)
       send_bitfield c;
     c.client_blocks_sent <- file.file_blocks_downloaded;
@@ -469,7 +482,9 @@
     
     ()
   with e ->
-      lprintf "Exception %s in client_parse_header\n" (Printexc2.to_string e);
+      BLOG DEBUG : 
+       "Exception %s in client_parse_header\n" (Printexc2.to_string e)
+      ELOG;
       close sock (Closed_for_exception e);
       raise e
 
@@ -539,38 +554,47 @@
     let swarmer = Int64Swarmer.uploader_swarmer up in       
     
     let num, x,y, r = 
-      if !verbose_msg_clients then begin
-          lprintf "CLIENT %d: Finding new range to send\n" (client_num c);
-        end;
-      
-      if !verbose_swarming then begin
-          lprintf "Current download:\n  Current chunks: "; 
-          List.iter (fun (x,y) -> lprintf "%Ld-%Ld " x y) c.client_chunks;
-          lprintf "\n  Current ranges: ";
+      BLOG DEBUG (!verbose_msg_clients) : 
+        "CLIENT %d: Finding new range to send\n" (client_num c)
+      ELOG;
+      BLOG DEBUG (!verbose_swarming) # 
+	begin
+          BLOG DEBUG : "Current download:\n" ELOG;
+	  BLOG DEBUG : "Current chunks: " ELOG; 
+          List.iter (fun (x,y) -> ldebug "%Ld-%Ld" x y) c.client_chunks;
+          ldebug "\n";
+	  BLOG DEBUG : "Current ranges: " ELOG;
           List.iter (fun (p1,p2, r) ->
               let (x,y) = Int64Swarmer.range_range r 
               in
-              lprintf "%Ld-%Ld[%Ld-%Ld] " p1 p2 x y) c.client_ranges;
-          lprintf "\n  Current block: ";
+              ldebug "%Ld-%Ld[%Ld-%Ld] " p1 p2 x y) c.client_ranges;
+          ldebug "\n";
+	  BLOG DEBUG : "Current block: " ELOG;
           (match c.client_block with
-              None -> lprintf "none\n"
+              None -> ldebug "none\n"
             | Some b -> Int64Swarmer.print_block b);
-          lprintf "\n\nFinding Range: \n";
-        end;
+          ldebug "\n\n";
+	  BLOG DEBUG : "Finding Range: \n" ELOG;
+        end
+      ELOG;
       try
 (*We must find a block to request first, and then 
 	some range inside this block*)
         let rec iter () =
           match c.client_block with
             None -> 
-              if !verbose_swarming then
-                lprintf "No block\n";
+              BLOG DEBUG (!verbose_swarming) :
+                "No block\n"
+	      ELOG;
               update_client_bitmap c;
 (*Find a free block in the swarmer*)
               let b = Int64Swarmer.find_block up in
-              if !verbose_swarming then begin 
-                  lprintf "Block Found: "; Int64Swarmer.print_block b;
-                end; 
+              BLOG DEBUG (!verbose_swarming) #
+		begin 
+                  BLOG DEBUG : "Block Found: " ELOG;
+		  Int64Swarmer.print_block b;
+                end
+	      ELOG; 
               c.client_block <- Some b;
 (*We put the found block in client_block to 
 		request range in this block. (Useful for 
@@ -578,24 +602,29 @@
 	      *)	      
               iter ()
           | Some b ->
-              if !verbose_swarming then begin
-                  lprintf "Current Block: "; Int64Swarmer.print_block b;
-                end;
+	      BLOG DEBUG (!verbose_swarming) #
+	       begin
+                BLOG DEBUG : "Current Block: " ELOG;
+		Int64Swarmer.print_block b;
+               end
+	      ELOG;
               try
 (*Given a block find a range inside*)
                 let (x,y,r) = Int64Swarmer.find_range up in
                 c.client_ranges <- c.client_ranges @ [x,y, r];
 (*                Int64Swarmer.alloc_range r; *)
                 let num, b_begin, b_end = Int64Swarmer.block_block b in
-                if !verbose_swarming then
-                  lprintf "Asking %d For Range %Ld-%Ld\n" num x y;
+		  BLOG DEBUG (!verbose_swarming) :
+                    "Asking %d For Range %Ld-%Ld\n" num x y 
+		  ELOG;
                 
                 num, x -- b_begin, y -- x, r
               with Not_found ->
 (*If we don't find a range to request inside the block,
 		iter to choose another block*)
-                  if !verbose_swarming then 
-                    lprintf "Could not find range in current block\n";
+		BLOG DEBUG (!verbose_swarming) : 
+		  "Could not find range in current block\n"
+		ELOG;
 (*                  c.client_blocks <- List2.removeq b c.client_blocks; *)
                   c.client_block <- None;
                   iter ()
@@ -606,19 +635,20 @@
 	  file is finished (if there's missing pieces we can't decide
 	  that the file is finished because we didn't found 
 	  a block to ask)*)
-          
-          if !verbose_swarming then
-            lprintf "Unable to get a block !!\n";
-          Int64Swarmer.compute_bitmap swarmer;
-          check_finished swarmer file;
-          raise Not_found
+        BLOG DEBUG (!verbose_swarming) :
+          "Unable to get a block !!\n"
+	ELOG;
+        Int64Swarmer.compute_bitmap swarmer;
+        check_finished swarmer file;
+        raise Not_found
     in
     send_client c (Request (num,x,y));
-    if !verbose_msg_clients then
-      lprintf "CLIENT %d: Asking %s For Range %Ld-%Ld\n"
+      BLOG DEBUG (!verbose_msg_clients) :
+	"CLIENT %d: Asking %s For Range %Ld-%Ld\n"
         (client_num c)
-      (Sha1.to_string c.client_uid) 
-      x y
+	(Sha1.to_string c.client_uid) 
+	x y
+      ELOG
 
 
 
@@ -629,15 +659,18 @@
   @param msg The message sent by the client
 *)
 and client_to_client c sock msg = 
-  if !verbose_msg_clients then begin
+  BLOG DEBUG (!verbose_msg_clients) #
+    begin
       let (timeout, next) = get_rtimeout sock in
-      lprintf "CLIENT %d: (%d, %d,%d) Received " 
+      BLOG DEBUG : "CLIENT %d: (%d, %d,%d) Received " 
         (client_num c)
       (last_time ())
       (int_of_float timeout)
-      (int_of_float next);
+      (int_of_float next)
+      ELOG;
       bt_print msg;
-    end;
+    end
+  ELOG;
   
   let file = c.client_file in
 (*  if c.client_blocks_sent != file.file_blocks_downloaded then begin
@@ -667,16 +700,17 @@
                 None -> assert false
               | Some up -> up in 
             let swarmer = Int64Swarmer.uploader_swarmer up in       
-            
-            if !verbose_msg_clients then 
+            BLOG DEBUG (!verbose_msg_clients) #
               (match c.client_ranges with
-                  [] -> lprintf "EMPTY Ranges !!!\n"
+                  [] -> BLOG DEBUG : "EMPTY Ranges !!!\n" ELOG
                 | (p1,p2,r) :: _ -> 
                     let (x,y) = Int64Swarmer.range_range r in
-                    lprintf "Current range %Ld [%d] (asked %Ld-%Ld[%Ld-%Ld])\n"
+                    BLOG DEBUG : "Current range %Ld [%d] (asked %Ld-%Ld[%Ld-%Ld])\n"
                       position len
                       p1 p2 x y 
-              );
+		    ELOG
+              )
+	    ELOG;
             
             let old_downloaded = 
               Int64Swarmer.downloaded swarmer in
@@ -691,17 +725,18 @@
             c.client_downloaded <- c.client_downloaded ++ 
                (new_downloaded -- old_downloaded);
             Rate.update c.client_downloaded_rate  (float_of_int len);
-            
-            if !verbose_msg_clients then 
+            BLOG DEBUG ( !verbose_msg_clients ) #
               (match c.client_ranges with
-                  [] -> lprintf "EMPTY Ranges !!!\n"
+                  [] -> BLOG DEBUG : "EMPTY Ranges !!!\n" ELOG
                 | (p1,p2,r) :: _ -> 
                     let (x,y) = Int64Swarmer.range_range r in
-                    lprintf "Received %Ld [%d] %Ld-%Ld[%Ld-%Ld] -> %Ld\n"
+                    BLOG DEBUG : "Received %Ld [%d] %Ld-%Ld[%Ld-%Ld] -> %Ld\n"
                       position len
                       p1 p2 x y 
-                      (new_downloaded -- old_downloaded)
-              );
+                      (new_downloaded -- old_downloaded) 
+		    ELOG
+              )
+	    ELOG;
             
             
             if new_downloaded <> old_downloaded then
@@ -765,10 +800,12 @@
             c.client_interesting <- true;
         done;
         
-        if !verbose_msg_clients then 
-          lprintf "BitField translated\n";
-        if !verbose_msg_clients then 
-          lprintf "Old BitField Unregistered\n";
+	  BLOG DEBUG (!verbose_msg_clients) :
+            "BitField translated\n"
+	  ELOG;
+	  BLOG DEBUG (!verbose_msg_clients) :
+	    "Old BitField Unregistered\n"
+	  ELOG;
         (match c.client_uploader with
             None -> assert false
           | Some up ->
@@ -779,8 +816,11 @@
         if c.client_incoming then
           send_bitfield c;
         send_interested c;
-        if !verbose_msg_clients then 
-          lprintf "New BitField Registered\n";
+	
+	BLOG DEBUG (!verbose_msg_clients) :
+          "New BitField Registered\n"
+	ELOG;
+
 (*        for i = 1 to max_range_requests - List.length c.client_ranges do
           (try get_from_client sock c with _ -> ())
         done*)
@@ -876,7 +916,7 @@
     
     | Cancel _ -> ()
   with e ->
-      lprintf "Error %s while handling MESSAGE\n" (Printexc2.to_string e)
+      BLOG DEBUG : "Error %s while handling MESSAGE\n" (Printexc2.to_string e) ELOG
       
 
 
@@ -894,13 +934,13 @@
       let token =
         add_pending_connection connection_manager (fun token ->
             try
-              if !verbose_msg_clients then begin
-                  lprintf "CLIENT %d: connect_client\n" (client_num c);
-                end;
+	      BLOG DEBUG (!verbose_msg_clients) :
+		"CLIENT %d: connect_client\n" (client_num c)
+	      ELOG;	      
               let (ip,port) = c.client_host in
-              if !verbose_msg_clients then begin
-                  lprintf "connecting %s:%d\n" (Ip.to_string ip) port; 
-                end;
+	      BLOG DEBUG (!verbose_msg_clients) :
+		"connecting %s:%d\n" (Ip.to_string ip) port
+	      ELOG;
               connection_try c.client_connection_control;
                 begin
                   let sock = connect token "bittorrent download" 
@@ -908,14 +948,15 @@
                       (fun sock event ->
                         match event with
                           BASIC_EVENT LTIMEOUT ->
-                            if !verbose_msg_clients then
-                              lprintf "CLIENT %d: LIFETIME\n" (client_num c);
+			    BLOG DEBUG (!verbose_msg_clients) :
+                              "CLIENT %d: LIFETIME\n" (client_num c)
+			    ELOG;
                             close sock Closed_for_timeout
                         | BASIC_EVENT RTIMEOUT ->
-                            if !verbose_msg_clients then
-                              lprintf "CLIENT %d: RTIMEOUT (%d)\n" (client_num c)
-                              (last_time ())
-                              ;
+			    BLOG DEBUG (!verbose_msg_clients) :
+			      "CLIENT %d: RTIMEOUT (%d)\n" (client_num c)
+                            (last_time ())
+			    ELOG;
                             close sock Closed_for_timeout
                         | BASIC_EVENT (CLOSED r) ->
                             begin
@@ -934,9 +975,9 @@
                   TcpBufferedSocket.set_rtimeout sock 30.;
                   let file = c.client_file in
                   
-                  if !verbose_msg_clients then begin
-                      lprintf "READY TO DOWNLOAD FILE\n";
-                    end;
+		  BLOG DEBUG (!verbose_msg_clients) :
+		    "READY TO DOWNLOAD FILE\n"
+           	  ELOG;		    
                   
                   send_init !!client_uid file.file_id sock;
 (* Fabrice: Initialize the client bitmap and uploader fields to <> None *)
@@ -950,8 +991,10 @@
                     (BTHeader (client_parse_header !counter (ref (Some c)) true))
                 end
             with e ->
-                lprintf "Exception %s while connecting to client\n" 
-                  (Printexc2.to_string e);
+              BLOG DEBUG : 
+	        "Exception %s while connecting to client\n" 
+                (Printexc2.to_string e) 
+	      ELOG;
                 disconnect_client c (Closed_for_exception e)
         );
 (*Since this is a pending connection put ConnectionWaiting
@@ -979,18 +1022,20 @@
 	      the TcpServerSocket means that a new client try 
 		to connect to us*)
 	      let ip = (Ip.of_inet_addr from_ip) in 
-              lprintf "CONNECTION RECEIVED FROM %s\n"
+              BLOG DEBUG : 
+		"CONNECTION RECEIVED FROM %s\n"
                 (Ip.to_string (Ip.of_inet_addr from_ip))
-              ; 
+              ELOG; 
 (*Reject this connection if we don't want
 		to bypass the max_connection parameter*)
               if can_open_connection connection_manager && 
 		(match Ip_set.match_ip !Ip_set.bl ip with
 		     None -> true
 		   | Some br ->
-		       if !verbose_connect then
-			 lprintf "%s:%d blocked: %s\n"
-			   (Ip.to_string ip) from_port br.blocking_description;
+		       BLOG DEBUG (!verbose_connect) :
+		       "%s:%d blocked: %s\n"
+		       (Ip.to_string ip) from_port (br.blocking_description)
+		       ELOG;
 		       false)		
 	      then
                 begin
@@ -1035,8 +1080,10 @@
     listen_sock := s;
     ()
   with e ->
-      lprintf "Exception %s while init bittorrent server\n" 
-        (Printexc2.to_string e)
+    BLOG DEBUG : 
+      "Exception %s while init bittorrent server\n" 
+      (Printexc2.to_string e) 
+    ELOG
       
   
   
@@ -1071,7 +1118,7 @@
       try
         match c.client_sock with 
         | Connection sock -> 
-            lprintf "RESUME: Client is already conencted\n";
+            BLOG DEBUG : "RESUME: Client is already conencted\n" ELOG;
         | _ ->
             (try 
 	       (*test if we can connect client according to the its 
@@ -1100,14 +1147,14 @@
   we really ask sources to the tracker
 *)
 let get_sources_from_tracker file = 
-  lprintf "get_sources_from_tracker\n";
+  BLOG DEBUG : "get_sources_from_tracker\n" ELOG;
   let f filename = 
 (*This is the function which will be called by the http client
 for parsing the response*)
-    lprintf "Filename %s\n" filename;
+    BLOG DEBUG : "Filename %s\n" filename ELOG;
     let v = Bencode.decode (File.to_string filename) in
     
-    lprintf "Received: %s\n" (Bencode.print v);
+    BLOG DEBUG : "Received: %s\n" (Bencode.print v) ELOG;
     let interval = ref 600 in
     match v with
       Dictionary list ->
@@ -1139,15 +1186,18 @@
 			   (match match_ip !Ip_set.bl !peer_ip with
 				None -> true
 			      | Some br ->
-				  if !verbose_connect then
-				    lprintf "%s:%d blocked: %s\n"
-				      (Ip.to_string !peer_ip) !port br.blocking_description;
+				  BLOG DEBUG (!verbose_connect) :
+				    "%s:%d blocked: %s\n"
+				  (Ip.to_string !peer_ip) (!port) (br.blocking_description)
+				  ELOG;
 				  false)
 			then
                           let c = new_client file !peer_id (!peer_ip,!port)
                           in
-                          lprintf "Received %s:%d\n" (Ip.to_string !peer_ip)
-                          !port;
+                          BLOG DEBUG :
+			    "Received %s:%d\n" (Ip.to_string !peer_ip)
+                            (!port)
+			  ELOG;
                           ()
                     
                     
@@ -1195,7 +1245,7 @@
               (try 
                   connect_tracker file "completed" (fun _ -> ())
                 with _ -> ())
-          | s -> lprintf "Other state %s!!\n" (string_of_state s)
+          | s -> BLOG DEBUG : "Other state %s!!\n" (string_of_state s) ELOG
       ) !current_files
       
 let upload_buffer = String.create 100000
@@ -1303,8 +1353,9 @@
       file_stop file
   );
   client_ops.op_client_enter_upload_queue <- (fun c ->
-      if !verbose_msg_clients then
-        lprintf "CLIENT %d: client_enter_upload_queue\n" (client_num c);
+      BLOG DEBUG (!verbose_msg_clients) :
+        "CLIENT %d: client_enter_upload_queue\n" (client_num c) 
+      ELOG;
       ready_for_upload (as_client c));
   network.op_network_connected_servers <- (fun _ -> []);
 


--- orig/src/networks/bittorrent/bTComplexOptions.ml
+++ mod/src/networks/bittorrent/bTComplexOptions.ml
@@ -119,8 +119,8 @@
       file.file_chunks <- get_value "file_hashes" (value_to_array
           (from_value Sha1.option))
     with e -> 
-        lprintf "Exception %s while loading chunks\n"
-          (Printexc2.to_string e); 
+        BLOG DEBUG : "Exception %s while loading chunks\n"
+          (Printexc2.to_string e) ELOG; 
   );
   
   (match file.file_swarmer with
@@ -137,8 +137,8 @@
         (get_value  "file_sources" (
           value_to_list (ClientOption.of_value file)))
     with e -> 
-        lprintf "Exception %s while loading sources\n"
-          (Printexc2.to_string e); 
+       BLOG DEBUG : "Exception %s while loading sources\n"
+          (Printexc2.to_string e) ELOG;
 );
   as_file file
   


--- orig/src/networks/bittorrent/bTGlobals.ml
+++ mod/src/networks/bittorrent/bTGlobals.ml
@@ -179,15 +179,23 @@
   );
   Int64Swarmer.set_verifier swarmer (fun num begin_pos end_pos ->
       if file.file_chunks = [||] then raise Not_found;
-      lprintf "Sha1 to compute: %d %Ld-%Ld\n" num begin_pos end_pos;
+      BLOG DEBUG : "Sha1 to compute: %d %Ld-%Ld\n" num begin_pos end_pos ELOG;
       Unix32.flush_fd (file_fd file);
       let sha1 = Sha1.digest_subfile (file_fd file) 
         begin_pos (end_pos -- begin_pos) in
       let result = sha1 = file.file_chunks.(num) in
-      lprintf "Sha1 computed: %s against %s = %s\n"
-        (Sha1.to_string sha1) (Sha1.to_string file.file_chunks.(num))
-      (if result then "VERIFIED" else "CORRUPTED");
-      if result then begin
+	(if result then 
+	   BLOG DEBUG :
+	     "Sha1 computed: %s against %s = VERIFIED\n"
+             (Sha1.to_string sha1) (Sha1.to_string file.file_chunks.(num))
+	     ELOG;
+	 else 
+	   BLOG INFO :
+	     "Sha1 computed: %s against %s = CORRUPTED\n"
+             (Sha1.to_string sha1) (Sha1.to_string file.file_chunks.(num))
+	     ELOG; 
+        );
+	if result then begin
           file.file_blocks_downloaded <- (num, begin_pos, end_pos) :: 
           file.file_blocks_downloaded;
           file_must_update file;


--- orig/src/networks/bittorrent/bTInteractive.ml
+++ mod/src/networks/bittorrent/bTInteractive.ml
@@ -160,10 +160,10 @@
 (*This is the function which will be called by the http client
 for parsing the response*)
 (* Intrested only in interval*)
-  lprintf "Filename %s\n" filename;
+  BLOG DEBUG : "Filename %s\n" filename ELOG;
   let v = Bencode.decode (File.to_string filename) in
 
-  lprintf "Received: %s\n" (Bencode.print v);
+  BLOG DEBUG : "Received: %s\n" (Bencode.print v) ELOG;
   let interval = ref 600 in
   match v with
     Dictionary list ->
@@ -171,7 +171,7 @@
           match (key, value) with
             String "interval", Int n ->
               file.file_tracker_interval <- Int64.to_int n;
-              lprintf ".. interval %d ..\n" file.file_tracker_interval
+              BLOG DEBUG : ".. interval %d ..\n" (file.file_tracker_interval) ELOG
           | _ -> ()
       ) list;
   | _ -> assert false
@@ -190,7 +190,7 @@
       else
         Unix32.create_rw filename
     in
-    lprintf "Sharing file %s\n" filename;
+     BLOG INFO : "Sharing file %s\n" filename ELOG;
     
     
     let file = new_file file_id torrent.torrent_name 
@@ -207,7 +207,6 @@
     let verified = String.make (String.length verified) '3' in
     Int64Swarmer.set_verified_bitmap swarmer verified;
 
-    lprintf "......\n";
     file.file_files <- torrent.torrent_files;
     file.file_chunks <- torrent.torrent_pieces;
     BTClients.connect_tracker file "completed" 
@@ -217,7 +216,7 @@
 (* Call one minute after start, and then every 20 minutes. Should 
   automatically contact the tracker. *)    
 let share_files _ =
-  lprintf "BTInteractive.share_files\n";
+  BLOG DEBUG : "BTInteractive.share_files\n" ELOG;
   List.iter (fun dir ->
       let filenames = Unix2.list_directory dir in
       List.iter (fun file ->
@@ -230,14 +229,14 @@
 let _ =
   network.op_network_parse_url <- (fun url ->
       let ext = String.lowercase (Filename2.last_extension url) in
-      lprintf "Last extension: %s\n" ext;
+      BLOG DEBUG : "Last extension: %s\n" ext ELOG;
       if ext = ".torrent" || ext = ".tor" then
         try
-          lprintf "Trying to load %s\n" url;
+          BLOG INFO : "Trying to load %s\n" url ELOG;
           load_torrent_file url;
           true
         with e ->
-            lprintf "Exception %s while loading\n" (Printexc2.to_string e);
+            BLOG DEBUG : "Exception %s while loading\n" (Printexc2.to_string e) ELOG;
             let module H = Http_client in
             let r = {
                 H.basic_request with
@@ -248,7 +247,7 @@
               } in
             
             H.wget r load_torrent_file;
-            lprintf "wget started\n";
+            BLOG INFO : "Initiated an http request to get %s\n" url ELOG;
             
             true
       else
@@ -368,13 +367,13 @@
         let torrent = Filename.concat tracked_directory 
             (Printf.sprintf "%s.torrent" basename)
         in
-        lprintf "1\n";
+        BLOG DEBUG : "generate torrent...\n" ELOG;
         BTTracker.generate_torrent announce torrent filename;
-        lprintf "2\n";
+        BLOG DEBUG : "scan tracked directory...\n" ELOG;
         BTTracker.scan_tracked_directory ();
-        lprintf "3\n";
+        BLOG DEBUG : "try share file...\n" ELOG;
         try_share_file torrent;
-        lprintf "4\n";
+        BLOG DEBUG : "end of compute torrent\n" ELOG;
         ".torrent file generated"
     ), _s " <filename> : generate the corresponding <filename>.torrent file
 in torrents/tracked/. The file is automatically tracked, and seeded if
@@ -416,4 +415,4 @@
   | opcode -> failwith (Printf.sprintf "BT: Unknown message opcode %d" opcode)
   
 let _ =
-  network.op_network_gui_message <- gui_message
\ Pas de fin de ligne à la fin du fichier.
+  network.op_network_gui_message <- gui_message


--- orig/src/networks/bittorrent/bTMain.ml
+++ mod/src/networks/bittorrent/bTMain.ml
@@ -50,10 +50,10 @@
     end
     
 let enable () =
-  lprintf "enable\n";
+  BLOG DEBUG : "enable\n" ELOG;
   if not !is_enabled then
     let enabler = ref true in
-    lprintf "enabling...\n";
+    BLOG INFO : "enabling...\n" ELOG;
     Unix2.safe_mkdir "torrents";
     Unix2.safe_mkdir downloads_directory;
     Unix2.safe_mkdir tracked_directory;  
@@ -62,8 +62,8 @@
     if !!tracker_port > 0 then (
         try BTTracker.start_tracker () 
         with e ->
-            lprintf "Exception in BTTracker.start_tracker: %s\n"
-              (Printexc2.to_string e));
+            BLOG DEBUG : "Exception in BTTracker.start_tracker: %s\n"
+              (Printexc2.to_string e) ELOG);
     add_infinite_timer 1200. (fun _ ->
         BTInteractive.share_files ();
         BTTracker.clean_tracker_timer ());
@@ -88,7 +88,6 @@
 *)
     
 
-    lprintf "XXXXXXXXXXXXXXX\n";
     BTClients.recover_files ();  
     add_session_timer enabler 60.0 (fun timer ->
         BTClients.recover_files ();
@@ -109,6 +108,7 @@
   );
 
   BTClients.listen ();
+  BLOG INFO : "enabled\n" ELOG;
   ()
   
 let _ =
@@ -146,4 +146,4 @@
   
   
 let main (toto: int) = ()
-  
\ Pas de fin de ligne à la fin du fichier.
+  


--- orig/src/networks/bittorrent/bTProtocol.ml
+++ mod/src/networks/bittorrent/bTProtocol.ml
@@ -254,20 +254,22 @@
 | Ping  
 
   
+(*This function will print a message in the 
+debug log level without 'DEBUG :' appended*)
 let bt_print msg =
   match msg with
-  | Choke -> lprintf "Choke\n"
-  | Unchoke -> lprintf "Unchoke\n"
-  | Interested -> lprintf "Interested\n"
-  | NotInterested -> lprintf "NotInterested\n"
-  | Have n -> lprintf "Have %Ld\n" n
-  | BitField s -> lprintf "BitField %s\n" (String.escaped s)
+  | Choke -> ldebug "Choke\n"
+  | Unchoke -> ldebug "Unchoke\n"
+  | Interested -> ldebug "Interested\n"
+  | NotInterested -> ldebug "NotInterested\n"
+  | Have n -> ldebug "Have %Ld\n" n
+  | BitField s -> ldebug "BitField %s\n" (String.escaped s)
   | Request (index, offset, len) -> 
-      lprintf "Request %d %Ld[%Ld]\n" index offset len
+      ldebug "Request %d %Ld[%Ld]\n" index offset len 
   | Piece (index, offset, s, pos, len) -> 
-      lprintf "Piece %d %Ld[%d]\n" index offset len
-  | Cancel _ -> lprintf "Cancel\n"
-  | Ping   -> lprintf "Ping\n"
+      ldebug "Piece %d %Ld[%d]\n" index offset len
+  | Cancel _ -> ldebug "Cancel\n"
+  | Ping   -> ldebug "Ping\n"
     
 let bt_parser opcode m = 
   match opcode with
@@ -293,7 +295,7 @@
         let msg_len = get_int b.buf b.pos in
         if msg_len < 0 then
           begin
-            lprintf "BT: Unknown message dropped!!\n";
+            BLOG DEBUG : "BT: Unknown message dropped!!\n" ELOG;
             dump (String.sub b.buf b.pos b.len);
             buf_used b b.len;
           end
@@ -323,8 +325,8 @@
     with 
     | Not_found -> ()
     with e ->
-        lprintf "Exception %s in bt_handler\n"
-          (Printexc2.to_string e)
+        BLOG DEBUG : "Exception %s in bt_handler\n"
+          (Printexc2.to_string e) ELOG
         
 let handlers info gconn =
   let rec iter_read sock nread =
@@ -442,14 +444,17 @@
         end;
         let s = Buffer.contents buf in
         str_int s 0 (String.length s - 4);
-        if !verbose_msg_clients then begin
-            bt_print msg;
-          end;
+	  BLOG DEBUG (!verbose_msg_clients) #
+	    begin
+	    BLOG DEBUG : "Sent to client : " ELOG;
+            bt_print msg
+	    end
+	  ELOG;
 (*        dump s; *)
         write_string sock s
   with e ->
-      lprintf "CLIENT : Error %s in send_client\n"
-        (Printexc2.to_string e)
+      BLOG DEBUG : "CLIENT : Error %s in send_client\n"
+        (Printexc2.to_string e) ELOG
 )
 
 let zero8 = String.make 8 '\000'


--- orig/src/networks/bittorrent/bTTracker.ml
+++ mod/src/networks/bittorrent/bTTracker.ml
@@ -484,9 +484,9 @@
       base_ref = "";
       default = http_handler;      
     } in
-  let sock = TcpServerSocket.create "BT tracker"
-      (Ip.to_inet_addr !!client_bind_addr) !!tracker_port (Http_server.handler config) in
-  tracker_sock := Some sock;
+  let sock = find_port "BT tracker"
+      !!client_bind_addr tracker_port (Http_server.handler config) in
+  tracker_sock := sock;
   scan_tracked_directory ();
   ()
 



