Add type annotations to `clientConnect.ml`
[hiphop-php.git] / hphp / hack / src / server / serverDebug.ml
blobe314358e1d651fd2eb66ec393ee4393561ac8675
1 (**
2 * Copyright (c) 2015, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 open Core_kernel
11 [@@@warning "-52"] (* we have no alternative but to depend on Sys_error strings *)
12 let log genv msg_thunk =
13 Option.iter genv.ServerEnv.debug_channels begin fun (_ic, oc) ->
14 (* The input is read using input_line, hence we append a trailing
15 * newline *)
16 (* We use a thunk so that expensive computations don't slow down the
17 * server when the debug listener isn't attached *)
18 let msg = msg_thunk () in
19 try
20 Out_channel.output_string oc ((Hh_json.json_to_string msg) ^ "\n");
21 Out_channel.flush oc;
22 with Sys_error "Broken pipe" -> begin
23 Hh_logger.log "Debug listener has gone away.";
24 genv.ServerEnv.debug_channels <- None;
25 end
26 end
27 [@@@warning "+52"] (* CARE! scope of suppression should be only 'log' *)
29 let info genv msg =
30 let open Hh_json in
31 let msg = JSON_Object [
32 "type", JSON_String "info";
33 "data", JSON_String msg;
34 ] in
35 log genv (fun () -> msg)
37 let say_hello genv = info genv "hello"