2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
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
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
20 Out_channel.output_string oc
((Hh_json.json_to_string
msg) ^
"\n");
22 with Sys_error
"Broken pipe" -> begin
23 Hh_logger.log "Debug listener has gone away.";
24 genv
.ServerEnv.debug_channels
<- None
;
27 [@@@warning
"+52"] (* CARE! scope of suppression should be only 'log' *)
31 let msg = JSON_Object
[
32 "type", JSON_String
"info";
33 "data", JSON_String
msg;
35 log genv
(fun () -> msg)
37 let say_hello genv
= info genv
"hello"