1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 Nomadic Labs <contact@nomadic-labs.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. *)(* *)(*****************************************************************************)exceptionIncorrect_log_rules_syntaxexceptionIncorrect_log_rules_not_a_levelexceptionIncorrect_log_rules_missing_levelexceptionIncorrect_log_rules_missing_patterntyperules=(string*Internal_event.Level.t)listletfind_log_rulesdefault=matchSys.(getenv_opt"TEZOS_LOG",getenv_opt"LWT_LOG")with|Somerules,None->("environment variable TEZOS_LOG",Somerules)|None,Somerules->("environment variable LWT_LOG",Somerules)|None,None->("configuration file",default)|Somerules,Some_->Format.eprintf"@[<v 2>@{<warning>@{<title>Warning@}@} Both environment variables \
TEZOS_LOG and LWT_LOG defined, using TEZOS_LOG.@]@\n\
@.";("environment variable TEZOS_LOG",Somerules)letparse_ruless=letrules=String.split_on_char';'sinletarrow_regexp=Re.(compile(Perl.re"->"))inList.filter_map(funrule->ifString.trimrule=""thenNoneelseletpattern,level=matchRe.(split_fullarrow_regexp)rule|>List.map(function|`Delim_ass->s|`Textt->`Text(String.trimt))with|[`Delim_;`Text_]|[`Text"";`Delim_;`Text_]->raiseIncorrect_log_rules_missing_pattern|[`Text_;`Delim_]|[`Text_;`Delim_;`Text""]->raiseIncorrect_log_rules_missing_level|[`Text"*";`Delim_;`Textlevel]->("",level)|[`Textpattern;`Delim_;`Textlevel]->(pattern,level)|[`Textlevel]->("",level)|_->raiseIncorrect_log_rules_syntaxinletlevel=matchInternal_event.Level.of_stringlevelwith|None->raiseIncorrect_log_rules_not_a_level|Somelvl->lvlinSome(pattern,level))rules