123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openTezos_error_monad.TzLwtreslibopenTezos_event_loggingopenError_monadmoduleConfiguration=structincludeTezos_base.Internal_event_configletof_filepath=letopenLwt_result_syntaxinlet*json=Lwt_utils_unix.Json.read_filepathinprotect(fun()->return(Data_encoding.Json.destructencodingjson))endletenv_var_name="TEZOS_EVENTS_CONFIG"letinit?lwt_log_sink?(configuration=Configuration.default)()=let_=(* This is just here to force the linking (and hence
initialization) of all these modules: *)[File_descriptor_sink.Sink_implementation_path.uri_scheme;File_event_sink.Sink_implementation.uri_scheme;]inletopenLwt_result_syntaxinlet*!r=let*()=Lwt_result.ok@@Lwt_log_sink_unix.initialize?cfg:lwt_log_sink()inlet*()=matchSys.(getenv_optenv_var_name)with|None->return_unit|Somes->leturis=TzString.split_no_empty' 's|>List.concat_map(TzString.split_no_empty'\n')|>List.concat_map(TzString.split_no_empty'\t')|>List.filter((<>)"")|>List.mapUri.of_stringinlet*()=List.iter_es(funuri->matchUri.schemeuriwith|None->let*cfg=Configuration.of_file(Uri.pathuri)inConfiguration.applycfg|Some_->Internal_event.All_sinks.activateuri)urisinInternal_event.Debug_event.(emit(make"Loaded URIs from environment"~attach:(`O[("variable",`Stringenv_var_name);("value",`Strings)])))inConfiguration.applyconfigurationinmatchrwith|Ok()->Lwt.return_unit|Errorel->Format.kasprintfLwt.fail_with"ERROR@ Initializing Internal_event_unix:@ %a\n%!"Error_monad.pp_print_traceelletclose()=letopenLwt_syntaxinlet*r=Internal_event.All_sinks.close()inmatchrwith|Ok()->Lwt.return_unit|Errorel->Format.kasprintfLwt.fail_with"ERROR@ closing Internal_event_unix:@ %a\n%!"Error_monad.pp_print_traceel