Commits

Yaron Minsky  committed 0e63431

added debug logging

  • Participants
  • Parent commits f480ece

Comments (0)

Files changed (1)

 open Core.Std
 open Async.Std
+module Log = Log.Global
 
 let send_update w u =
   Writer.write w (Update.to_line u);
          >>= function
            | `Eof -> Deferred.unit
            | `Ok pname ->
+             Log.debug "user logon %s" pname;
              let pname = Player_name.of_string pname in
              state := State.register_player !state pname;
              let rec loop () =
                Reader.read_line r >>= function
                  | `Eof -> Deferred.unit
                  | `Ok line ->
+                   Log.debug "line: %s" line;
                    begin match Action.of_line line with
                    | Error e ->
                      let u = Update.of_error e in
                    loop ()
              in
              loop ()
+             >>| fun () ->
+             Log.debug "Client disconnected"
       )
   in
   ignore (host_and_port : (Socket.Address.Inet.t, int) Tcp.Server.t Deferred.t);
     Command.Spec.(
       empty
       +> flag "-port" (optional_with_default default_port int)
-        ~doc:(sprintf " Port to listen on (default %d)" default_port)
+           ~doc:(sprintf " Port to listen on (default %d)" default_port)
+      +> flag "-debug" no_arg
+           ~doc:"Turns on debug logging"
     )
-    (fun port () -> run ~port)
+    (fun port debug () ->
+       if debug then Log.set_level `Debug;
+       run ~port
+    )