123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184(*****************************************************************************)(* *)(* 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))end(* FIXME https://gitlab.com/tezos/tezos/-/issues/4837
This environment variable is problematic when the octez-node in not
run with [Singleprocess]. *)letenv_var_name="TEZOS_EVENTS_CONFIG"moduleEvent=structincludeInternal_event.Simpleletsection=["internal_event_unix"]letloaded_from_env=declare_2~section~name:"uri_loaded_from_env"~msg:"Loaded URIs from environment"~level:Notice("variable",Data_encoding.string)("value",Data_encoding.string)endletinit_raw~internal_events()=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*()=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)inInternal_event_config.applycfg|Some_->Internal_event.All_sinks.activateuri)urisinlet*!()=Event.(emitloaded_from_env(env_var_name,s))inreturn_unitinConfiguration.applyinternal_eventsinmatchrwith|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_traceelopenFilename.Infixletmake_default_internal_events~rules~verbosity~colors~(log_output:Logs_simple_config.Output.t)~daily_logs_path=(* By default the node has two logs output:
- on the configured [log_output] using the configured [verbosity] and
a short pretty printing
- on disk, with a 7 days rotation with an info verbosity level and a
standard pretty printing *)letorigin,rules=Level_config_rules.find_log_rulesrulesinletsection_prefixes=matchruleswith|Somerules->(tryLevel_config_rules.parse_rulesruleswith_->Printf.ksprintfStdlib.failwith"Incorrect log rules defined in %s"origin)|None->[]inletuser_events=letkind=matchlog_outputwith|Stdout->`Stdout|Stderr->`Stderr|Filefp->`Pathfp|Null->`Null|Syslog_->`Syslog(Logs_simple_config.Output.to_stringlog_output)inInternal_event_config.make_config_uri~level:verbosity~section_prefixes~colors~format:"pp-short"kindinletsinks=[user_events]inletsinks=matchdaily_logs_pathwith|Somedaily_logs_path->letinternal_logs_events=Internal_event_config.make_config_uri~create_dirs:true~daily_logs:7~level:Info~format:"pp-rfc5424"(`Path(daily_logs_path//"daily.log"))ininternal_logs_events::sinks|None->sinksinInternal_event_config.make_customsinksletmake_with_defaults?verbosity?enable_default_daily_logs_at?(log_cfg=Logs_simple_config.default_cfg)()=make_default_internal_events~rules:log_cfg.rules~verbosity:(Option.valueverbosity~default:log_cfg.default_level)~colors:log_cfg.colors~log_output:log_cfg.output~daily_logs_path:enable_default_daily_logs_atletinit?config:(internal_events=make_with_defaults())()=letopenLwt_syntaxinlet*()=init_raw~internal_events()inreturn_unit