123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* 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. *)(* *)(*****************************************************************************)moduleOutput=structtypet=Null|Stdout|Stderr|Fileofstring|SyslogofSyslog.facilityletto_string:t->string=function|Null->"/dev/null"|Stdout->"stdout"|Stderr->"stderr"|Filefp->fp|SyslogAuth->"syslog:auth"|SyslogAuthpriv->"syslog:authpriv"|SyslogCron->"syslog:cron"|SyslogDaemon->"syslog:daemon"|SyslogFTP->"syslog:ftp"|SyslogKernel->"syslog:kernel"|SyslogLocal0->"syslog:local0"|SyslogLocal1->"syslog:local1"|SyslogLocal2->"syslog:local2"|SyslogLocal3->"syslog:local3"|SyslogLocal4->"syslog:local4"|SyslogLocal5->"syslog:local5"|SyslogLocal6->"syslog:local6"|SyslogLocal7->"syslog:local7"|SyslogLPR->"syslog:lpr"|SyslogMail->"syslog:mail"|SyslogNews->"syslog:news"|SyslogSyslog->"syslog:syslog"|SyslogUser->"syslog:user"|SyslogUUCP->"syslog:uucp"|SyslogNTP->"syslog:ntp"|SyslogSecurity->"syslog:security"|SyslogConsole->"syslog:console"letof_string:string->t=function|"/dev/null"|"null"->Null|"stdout"->Stdout|"stderr"->Stderr|"syslog:auth"->SyslogAuth|"syslog:authpriv"->SyslogAuthpriv|"syslog:cron"->SyslogCron|"syslog:daemon"->SyslogDaemon|"syslog:ftp"->SyslogFTP|"syslog:kernel"->SyslogKernel|"syslog:local0"->SyslogLocal0|"syslog:local1"->SyslogLocal1|"syslog:local2"->SyslogLocal2|"syslog:local3"->SyslogLocal3|"syslog:local4"->SyslogLocal4|"syslog:local5"->SyslogLocal5|"syslog:local6"->SyslogLocal6|"syslog:local7"->SyslogLocal7|"syslog:lpr"->SyslogLPR|"syslog:mail"->SyslogMail|"syslog:news"->SyslogNews|"syslog:syslog"->SyslogSyslog|"syslog:user"->SyslogUser|"syslog:uucp"->SyslogUUCP|"syslog:ntp"->SyslogNTP|"syslog:security"->SyslogSecurity|"syslog:console"->SyslogConsole(* | s when start_with "syslog:" FIXME error or warning. *)|fp->(* TODO check absolute path *)Filefpletencoding=letopenData_encodinginconvto_stringof_stringstringletof_stringstr=trySome(Data_encoding.Json.destructencoding(`Stringstr))with_->Noneletto_stringoutput=matchData_encoding.Json.constructencodingoutputwith|`Stringres->res|#Data_encoding.json->assertfalseletppfmtoutput=Format.fprintffmt"%s"(to_stringoutput)endtypecfg={output:Output.t;default_level:Internal_event.level;rules:stringoption;colors:bool;}letcreate_cfg?(output=Output.Stderr)?(default_level=Internal_event.Notice)?(colors=true)?rules()={output;default_level;rules;colors}letdefault_cfg=create_cfg()letcfg_encoding=letopenData_encodinginconv(fun{output;default_level;rules;colors}->(output,default_level,colors,rules))(fun(output,default_level,colors,rules)->{output;default_level;rules;colors})(obj4(dft"output"~description:"Output for the logging function. Either 'stdout', 'stderr' or the \
name of a log file ."Output.encodingdefault_cfg.output)(dft"level"~description:"Verbosity level: one of 'fatal', 'error', 'warn','notice', \
'info', 'debug'."Internal_event.Level.encodingdefault_cfg.default_level)(dft"colors"~description:"Enables light coloring in logs."Data_encoding.booldefault_cfg.colors)(opt"rules"~description:"Fine-grained logging instructions. Same format as described in \
`octez-node run --help`, DEBUG section. In the example below, \
sections 'p2p' and all sections starting by 'client' will have \
their messages logged up to the debug level, whereas the rest of \
log sections will be logged up to the notice level."string))