123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * INRIA, CNRS and contributors - Copyright 1999-2018 *)(* <O___,, * (see CREDITS file for the list of authors) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)(************************************************************************)(* Coq Language Server Protocol *)(* Copyright 2019 MINES ParisTech -- Dual License LGPL 2.1 / GPL3+ *)(* Copyright 2019-2022 Inria -- Dual License LGPL 2.1 / GPL3+ *)(* Written by: Emilio J. Gallego Arias *)(************************************************************************)letmut=Mutex.create()letdebug_chan=refNoneletstart_log~client_cbfile=letabs_file=Filename.concat(Sys.getcwd())fileintryletdebug_oc=open_outfileindebug_chan:=Some(debug_oc,Format.formatter_of_out_channeldebug_oc);client_cb(Format.asprintf"server log file %s created"abs_file)with_->client_cb(Format.asprintf"creation of server log file %s failed"abs_file)letend_log()=Option.iter(fun(oc,fmt)->Format.pp_print_flushfmt();Stdlib.flushoc;close_outoc)!debug_chan;debug_chan:=Noneletwith_logf=Option.iter(fun(_,fmt)->ffmt)!debug_chanletlog_errorhdrmsg=with_log(funfmt->Mutex.lockmut;Format.fprintffmt"[%s]: @[%s@]@\n%!"hdrmsg;Mutex.unlockmut)letlog_objecthdrobj=with_log(funfmt->Format.fprintffmt"[%s]: @[%a@]@\n%!"hdrYojson.Safe.(pretty_print~std:false)obj)