Source

core hello world / broker_server.ml

Diff from to

broker_server.ml

 (* First, we build the implementations *)
 
 let publish_impl (dir,_) msg =
+  Log.Global.info "Message published";
   return (Directory.publish dir msg)
 
 let subscribe_impl (dir,_) topic ~aborted =
+  Log.Global.info "Subscription started";
   return (
     match Directory.subscribe dir topic with
     | None -> Error "Unknown topic"
   )
 
 let dump_impl (dir,_) () =
+  Log.Global.info "Dump requested";
   return (Directory.dump dir)
 
 let shutdown_impl (_,stop) () =
+  Log.Global.info "Shutdown requested";
   Ivar.fill_if_empty stop ();
   return ()
 
 
 let command = Command.async_basic
   ~summary:"Start the message broker server"
-  Command.Spec.(empty +> Common.port_arg ())
+  Command.Spec.(
+    empty
+    +> Common.port_arg ()
+  )
   (fun port () ->
+    (* We use a blocking call to get the working directory, because the Async
+       scheduler isn't running yet.
+    *)
+    let basedir = Core.Std.Unix.getcwd () in
+(*
+    let finish_daemonize =
+      unstage
+        (Daemon.daemonize_wait ()
+           ~redirect_stdout:`Do_not_redirect
+           ~redirect_stderr:`Do_not_redirect
+           ~cd:basedir)
+    in
+*)
+    Log.Global.set_output
+      [ Log.Output.file `Text ~filename:(basedir ^/ "broker.log") ];
+    return () >>= fun () ->
+(*    finish_daemonize ();*)
+    Log.Global.info "Starting broker";
     let stop = Ivar.create () in
     let directory = Directory.create () in
+    Log.Global.info "Starting server";
     Common.start_server ()
       ~stop:(Ivar.read stop)
       ~port
   )
 
 let () = Command.run command
-
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.