diff --git a/manifest/main.ml b/manifest/main.ml index 8eb8680784a383260d9e4c847a3a2d9f55f45729..1c2cd03ab7a789ef02415da11b75f14bee795666 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -1875,12 +1875,13 @@ let octez_base_unix = [ octez_error_monad |> open_; octez_crypto; - octez_base |> open_; + octez_base |> open_ |> open_ ~m:"TzPervasives"; octez_hacl; octez_stdlib |> open_; octez_stdlib_unix |> open_; data_encoding |> open_; uri; + octez_event_logging |> open_; ] let _octez_base_tests = @@ -4098,6 +4099,7 @@ let octez_node_config = ~deps: [ octez_base |> open_ ~m:"TzPervasives" |> open_; + octez_base_unix |> open_; octez_stdlib_unix |> open_; octez_shell_services |> open_; octez_rpc_http |> open_; diff --git a/src/bin_node/node_reconstruct_command.ml b/src/bin_node/node_reconstruct_command.ml index e58accadf0c6ee7a3cc086261f6ad3a5751c6140..7687b836fd0e8f58cc790194bbec5bff678ec4c9 100644 --- a/src/bin_node/node_reconstruct_command.ml +++ b/src/bin_node/node_reconstruct_command.ml @@ -47,7 +47,7 @@ module Term = struct let process data_dir config_file sandbox_file progress_display_mode = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in let* data_dir, node_config = Shared_arg.resolve_data_dir_and_config_file ?data_dir ?config_file () in diff --git a/src/bin_node/node_replay_command.ml b/src/bin_node/node_replay_command.ml index 48454e934c1aac23adb2178b78e292bcdeb4700f..7b7098ebdfde71b21731e3132aa9b63387cfae15 100644 --- a/src/bin_node/node_replay_command.ml +++ b/src/bin_node/node_replay_command.ml @@ -372,8 +372,8 @@ let replay_one_block strict main_chain_store validator_process block = | No_metadata_hash _, _ | _, No_metadata_hash _ -> (* Nothing to compare *) return_unit -let replay ~singleprocess ~strict ~operation_metadata_size_limit - (config : Config_file.t) blocks = +let replay ~internal_events ~singleprocess ~strict + ~operation_metadata_size_limit (config : Config_file.t) blocks = let open Lwt_result_syntax in let store_root = Data_version.store_dir config.data_dir in let context_root = Data_version.context_dir config.data_dir in @@ -417,11 +417,7 @@ let replay ~singleprocess ~strict ~operation_metadata_size_limit process_path = Sys.executable_name; sandbox_parameters = None; dal_config = Tezos_crypto_dal.Cryptobox.Config.default; - log_config = - { - lwt_log_sink_unix = config.log; - internal_events = config.internal_events; - }; + log_config = {lwt_log_sink_unix = config.log; internal_events}; }) in let commit_genesis = @@ -479,11 +475,17 @@ let run ?verbosity ~singleprocess ~strict ~operation_metadata_size_limit ~filename:(Data_version.lock_file config.data_dir) @@ fun () -> (* Main loop *) + let log_cfg = + { + config.log with + default_level = Option.value verbosity ~default:config.log.default_level; + } + in + let internal_events = + Tezos_base_unix.Internal_event_unix.make_with_defaults () + in let*! () = - Log_config.init_internal_events_with_defaults - ?verbosity - ~log_cfg:config.log - () + Tezos_base_unix.Internal_event_unix.init ~log_cfg ~internal_events () in Updater.init (Data_version.protocol_dir config.data_dir) ; Lwt_exit.( @@ -491,6 +493,7 @@ let run ?verbosity ~singleprocess ~strict ~operation_metadata_size_limit @@ let*! res = protect (fun () -> replay + ~internal_events ~singleprocess ~strict ~operation_metadata_size_limit diff --git a/src/bin_node/node_run_command.ml b/src/bin_node/node_run_command.ml index 17ed3c619d9323171262bd363ecca22b55f95120..7c13494cbe805c7f734993f5666abb3b2cd1fa9b 100644 --- a/src/bin_node/node_run_command.ml +++ b/src/bin_node/node_run_command.ml @@ -508,21 +508,24 @@ let run ?verbosity ?sandbox ?target ?(cli_warnings = []) (config : Config_file.t) = let open Lwt_result_syntax in (* Main loop *) - let lwt_log_sink_unix, internal_events = - Log_config.make_internal_events_with_defaults - ~internal_events:(config.internal_events, config.data_dir) - ?verbosity - ~log_cfg:config.log + let log_cfg = + { + config.log with + default_level = Option.value verbosity ~default:config.log.default_level; + } + in + let internal_events = + Tezos_base_unix.Internal_event_unix.make_with_defaults + ~enable_default_daily_logs_at: + Filename.Infix.(config.data_dir // "daily_logs") + ?internal_events:config.internal_events () in let*! () = - Tezos_base_unix.Internal_event_unix.init - ~lwt_log_sink:lwt_log_sink_unix - ~configuration:internal_events - () + Tezos_base_unix.Internal_event_unix.init ~log_cfg ~internal_events () in let external_validator_log_config = - External_validation.{internal_events; lwt_log_sink_unix} + External_validation.{internal_events; lwt_log_sink_unix = log_cfg} in let*! () = Lwt_list.iter_s (fun evt -> Internal_event.Simple.emit evt ()) cli_warnings diff --git a/src/bin_node/node_snapshot_command.ml b/src/bin_node/node_snapshot_command.ml index e56f2468150425ca93e674fab94199236fb201c5..773381eb06c023c318074aa95b2b34914e1b0634 100644 --- a/src/bin_node/node_snapshot_command.ml +++ b/src/bin_node/node_snapshot_command.ml @@ -123,7 +123,7 @@ module Term = struct progress_display_mode = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in let* data_dir, node_config = Shared_arg.resolve_data_dir_and_config_file ?data_dir ?config_file () in @@ -160,7 +160,7 @@ module Term = struct block disable_check reconstruct sandbox_file progress_display_mode = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in let* data_dir, node_config = Shared_arg.resolve_data_dir_and_config_file ?data_dir ?config_file () in @@ -272,7 +272,7 @@ module Term = struct let get_info snapshot_path format_json = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in let* snapshot_path = check_snapshot_path snapshot_path in let* snapshot_header = Snapshots.read_snapshot_header ~snapshot_path in if format_json then diff --git a/src/bin_node/node_storage_command.ml b/src/bin_node/node_storage_command.ml index 572c2764cbdd7fe2d35a35bc51c40b2e75d158ca..86e81b67dbdbfb8cd797237961a251d0fa763ff5 100644 --- a/src/bin_node/node_storage_command.ml +++ b/src/bin_node/node_storage_command.ml @@ -178,7 +178,7 @@ module Term = struct let integrity_check_inodes config_file data_dir block = Shared_arg.process_command (let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in let* data_dir, node_config = Shared_arg.resolve_data_dir_and_config_file ?data_dir ?config_file () in @@ -223,7 +223,7 @@ module Term = struct let find_head config_file data_dir = Shared_arg.process_command (let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in let* data_dir, node_config = Shared_arg.resolve_data_dir_and_config_file ?data_dir ?config_file () in diff --git a/src/bin_node/node_upgrade_command.ml b/src/bin_node/node_upgrade_command.ml index ee77847db7fad9335e5e0eac5eb3aa0a21cd2a65..5d7789efc8c6b992b2b05e42d9c690f6d4fd5f8c 100644 --- a/src/bin_node/node_upgrade_command.ml +++ b/src/bin_node/node_upgrade_command.ml @@ -60,7 +60,7 @@ module Term = struct let process subcommand data_dir config_file status sandbox_file = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in match subcommand with | Storage -> ( let* data_dir, config = diff --git a/src/bin_proxy_server/proxy_server_main_run.ml b/src/bin_proxy_server/proxy_server_main_run.ml index 23ba6e23918fcdcb6875c5e554ebd5a276f3e005..7b2b6501d2c96cc2186119808c746f85d64fdb83 100644 --- a/src/bin_proxy_server/proxy_server_main_run.ml +++ b/src/bin_proxy_server/proxy_server_main_run.ml @@ -88,10 +88,7 @@ let launch_rpc_server dir {address; port; tls_cert_and_key; forwarding_endpoint} let run dir ({address; port; _} as args) = let open Lwt_result_syntax in - let log_cfg = Lwt_log_sink_unix.create_cfg () in - let*! () = - Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink:log_cfg () - in + let*! () = Tezos_base_unix.Internal_event_unix.init () in let node_downer = Lwt_exit.register_clean_up_callback ~loc:__LOC__ (fun _ -> Events.(emit shutting_down_proxy_server) ()) diff --git a/src/bin_signer/main_signer.ml b/src/bin_signer/main_signer.ml index be0d9eb99b154ff6c8991c0c707d226731244582..d7667f08203df4836505bc8dcac97f14ecb0819f 100644 --- a/src/bin_signer/main_signer.ml +++ b/src/bin_signer/main_signer.ml @@ -379,6 +379,8 @@ module Signer_config = struct let other_registrations = None + let default_daily_logs_path = None + let clic_commands ~base_dir ~config_commands:_ ~builtin_commands:_ ~other_commands ~require_auth = commands base_dir require_auth @ other_commands diff --git a/src/bin_snoop/main_snoop.ml b/src/bin_snoop/main_snoop.ml index 6367a2899dfc84ce7a9ad2fd4194701898603ea8..ec9656cdc292af298130d7c71c7c3c3e61d9f375 100644 --- a/src/bin_snoop/main_snoop.ml +++ b/src/bin_snoop/main_snoop.ml @@ -580,13 +580,7 @@ let codegen_check_definitions_cmd files = (* Entrypoint *) (* Activate logging system. *) -let () = - Lwt_main.run - @@ Tezos_base_unix.Internal_event_unix.( - init - ~lwt_log_sink:Lwt_log_sink_unix.default_cfg - ~configuration:Configuration.lwt_log) - () +let () = Lwt_main.run @@ Tezos_base_unix.Internal_event_unix.init () let () = if Commands.list_solvers then list_solvers Format.std_formatter ; diff --git a/src/lib_base/unix/dune b/src/lib_base/unix/dune index 3bcd6d4eb8e0c845092225bd468b6d3e39ad4a83..8a6cdb7f51130d4a460231c80486c2b9ff766247 100644 --- a/src/lib_base/unix/dune +++ b/src/lib_base/unix/dune @@ -13,11 +13,14 @@ tezos-stdlib tezos-stdlib-unix data-encoding - uri) + uri + tezos-event-logging) (flags (:standard) -open Tezos_error_monad -open Tezos_base + -open Tezos_base.TzPervasives -open Tezos_stdlib -open Tezos_stdlib_unix - -open Data_encoding)) + -open Data_encoding + -open Tezos_event_logging)) diff --git a/src/lib_base/unix/internal_event_unix.ml b/src/lib_base/unix/internal_event_unix.ml index e6a99da3e1a8de9bab8a052c20b820281e2443f9..40165e0cf96e96b2a01f85f2602abcc9c5fd7fa4 100644 --- a/src/lib_base/unix/internal_event_unix.ml +++ b/src/lib_base/unix/internal_event_unix.ml @@ -42,7 +42,7 @@ end run with [Singleprocess]. *) let env_var_name = "TEZOS_EVENTS_CONFIG" -let init ?lwt_log_sink ?(configuration = Configuration.lwt_log) () = +let init ?log_cfg ?(internal_events = Internal_event_config.lwt_log) () = let _ = (* This is just here to force the linking (and hence initialization) of all these modules: *) @@ -53,9 +53,7 @@ let init ?lwt_log_sink ?(configuration = Configuration.lwt_log) () = in let open Lwt_result_syntax in let*! r = - let* () = - Lwt_result.ok @@ Lwt_log_sink_unix.initialize ?cfg:lwt_log_sink () - in + let* () = Lwt_result.ok @@ Lwt_log_sink_unix.initialize ?cfg:log_cfg () in let* () = match Sys.(getenv_opt env_var_name) with | None -> return_unit @@ -73,7 +71,7 @@ let init ?lwt_log_sink ?(configuration = Configuration.lwt_log) () = match Uri.scheme uri with | None -> let* cfg = Configuration.of_file (Uri.path uri) in - Configuration.apply cfg + Internal_event_config.apply cfg | Some _ -> Internal_event.All_sinks.activate uri) uris in @@ -85,7 +83,7 @@ let init ?lwt_log_sink ?(configuration = Configuration.lwt_log) () = (`O [("variable", `String env_var_name); ("value", `String s)]))) in - Configuration.apply configuration + Configuration.apply internal_events in match r with | Ok () -> Lwt.return_unit @@ -107,3 +105,41 @@ let close () = "ERROR@ closing Internal_event_unix:@ %a\n%!" Error_monad.pp_print_trace el + +open Filename.Infix + +let make_default_internal_events daily_logs_path = + (* By default the node has two logs output: + - on stdout using Lwt_log using the configured verbosity + - on disk, with a 7 days rotation with an info verbosity level *) + Internal_event_config.make_custom + [ + Uri.make ~scheme:Internal_event.Lwt_log_sink.uri_scheme (); + Uri.make + ~scheme:"file-descriptor-path" + ~path:(daily_logs_path // "daily.log") + ~query: + [ + ("create-dirs", ["true"]); + ("daily-logs", ["7"]); + ("section-prefix", [":info"]); + ("format", ["pp"]); + ] + (); + ] + +let make_with_defaults ?internal_events ?enable_default_daily_logs_at () = + let internal_events = + match (internal_events, enable_default_daily_logs_at) with + | None, None -> Internal_event_config.lwt_log + | None, Some daily_logs_path -> make_default_internal_events daily_logs_path + | Some internal_events, _ -> internal_events + in + internal_events + +let init_with_defaults ?internal_events ?enable_default_daily_logs_at ?log_cfg + () = + let internal_events = + make_with_defaults ?internal_events ?enable_default_daily_logs_at () + in + init ?log_cfg ~internal_events () diff --git a/src/lib_base/unix/internal_event_unix.mli b/src/lib_base/unix/internal_event_unix.mli index f00128f41f3855835f4b586ef1aa87f52cb756c4..96129c1fd0c5750899c616a36b8715c72df34425 100644 --- a/src/lib_base/unix/internal_event_unix.mli +++ b/src/lib_base/unix/internal_event_unix.mli @@ -45,7 +45,7 @@ end val env_var_name : string (** Initialize the internal-event sinks by looking at the - [?configuration] argument and then at the (whitespace separated) list + [?internal_events] argument and then at the (whitespace separated) list of URIs in the ["TEZOS_EVENTS_CONFIG"] environment variable, if an URI does not have a scheme it is expected to be a path to a configuration JSON file (cf. {!Configuration.of_file}), e.g.: @@ -54,12 +54,43 @@ val env_var_name : string The function also initializes the {!Lwt_log_sink_unix} module (corresponding to the ["TEZOS_LOG"] environment variable). + + - [internal_events] is the value of configured sinks of command calling + init. + + - [log_cfg] is the configuration specific to the default sinks if + applicable. *) val init : - ?lwt_log_sink:Lwt_log_sink_unix.cfg -> - ?configuration:Configuration.t -> + ?log_cfg:Lwt_log_sink_unix.cfg -> + ?internal_events:Internal_event_config.t -> unit -> unit Lwt.t (** Call [close] on all the sinks. *) val close : unit -> unit Lwt.t + +(** [make_with_defaults ?enable_default_daily_logs_at ?internal_events ] creates + internal event configuration using default values depending on parameters. + + - If [internal_events] is provided, nothing is modified. Otherwise default + values are used. + + - [enable_default_daily_logs_at] adds daily rotating sink at the given path + with the following value: + ["file-descriptor-path:////daily.log + ?create-dirs=true&daily-logs=7§ion-prefix=info&format=pp"] *) + +val make_with_defaults : + ?internal_events:Internal_event_config.t -> + ?enable_default_daily_logs_at:string -> + unit -> + Internal_event_config.t + +(** Calls [init] with the same arguments as [make_with_defaults] *) +val init_with_defaults : + ?internal_events:Internal_event_config.t -> + ?enable_default_daily_logs_at:string -> + ?log_cfg:Lwt_log_sink_unix.cfg -> + unit -> + unit Lwt.t diff --git a/src/lib_client_base_unix/client_config.ml b/src/lib_client_base_unix/client_config.ml index 4cb6406aa77e0defab6a42ab8e4c94fd9c6ca2b8..4ffc6200afd32887607baffd80a52d60fd083e38 100644 --- a/src/lib_client_base_unix/client_config.ml +++ b/src/lib_client_base_unix/client_config.ml @@ -203,6 +203,8 @@ let default_endpoint = Uri.of_string "http://localhost:8732" let default_media_type = Media_type.Command_line.Any +let default_daily_logs_path = None + open Filename.Infix module Cfg_file = struct @@ -220,6 +222,7 @@ module Cfg_file = struct remote_signer : Uri.t option; confirmations : int option; password_filename : string option; + internal_events : Tezos_base.Internal_event_config.t option; } let default = @@ -234,6 +237,7 @@ module Cfg_file = struct remote_signer = None; confirmations = Some 0; password_filename = None; + internal_events = None; } open Data_encoding @@ -251,27 +255,30 @@ module Cfg_file = struct remote_signer; confirmations; password_filename; + internal_events; } -> - ( base_dir, - node_addr, - node_port, - tls, - media_type, - endpoint, - Some web_port, - remote_signer, - confirmations, - password_filename )) - (fun ( base_dir, - node_addr, - node_port, - tls, - media_type, - endpoint, - web_port, - remote_signer, - confirmations, - password_filename ) -> + ( ( base_dir, + node_addr, + node_port, + tls, + media_type, + endpoint, + Some web_port, + remote_signer, + confirmations, + password_filename ), + internal_events )) + (fun ( ( base_dir, + node_addr, + node_port, + tls, + media_type, + endpoint, + web_port, + remote_signer, + confirmations, + password_filename ), + internal_events ) -> let web_port = Option.value ~default:default.web_port web_port in { base_dir; @@ -284,18 +291,22 @@ module Cfg_file = struct remote_signer; confirmations; password_filename; + internal_events; }) - (obj10 - (req "base_dir" string) - (opt "node_addr" string) - (opt "node_port" uint16) - (opt "tls" bool) - (opt "media_type" Media_type.Command_line.encoding) - (opt "endpoint" Tezos_rpc.Encoding.uri_encoding) - (opt "web_port" uint16) - (opt "remote_signer" Tezos_rpc.Encoding.uri_encoding) - (opt "confirmations" int8) - (opt "password_filename" string)) + (merge_objs + (obj10 + (req "base_dir" string) + (opt "node_addr" string) + (opt "node_port" uint16) + (opt "tls" bool) + (opt "media_type" Media_type.Command_line.encoding) + (opt "endpoint" Tezos_rpc.Encoding.uri_encoding) + (opt "web_port" uint16) + (opt "remote_signer" Tezos_rpc.Encoding.uri_encoding) + (opt "confirmations" int8) + (opt "password_filename" string)) + (obj1 + (opt "internal_events" Tezos_base.Internal_event_config.encoding))) let from_json json = Data_encoding.Json.destruct encoding json diff --git a/src/lib_client_base_unix/client_main_run.ml b/src/lib_client_base_unix/client_main_run.ml index 5b1c0f139091a7a71356b8b476bcea517b306e5b..159883bba6836fb6cbeac04ed2b31e7aecdf8e0d 100644 --- a/src/lib_client_base_unix/client_main_run.ml +++ b/src/lib_client_base_unix/client_main_run.ml @@ -62,6 +62,8 @@ module type M = sig val default_base_dir : string + val default_daily_logs_path : string option + val default_media_type : Media_type.Command_line.t val other_registrations : @@ -413,7 +415,6 @@ let main (module C : M) ~select_commands = (if Unix.isatty Unix.stderr then Ansi else Plain) Short) ; warn_if_argv0_name_not_octez () ; - let*! () = Tezos_base_unix.Internal_event_unix.init () in let*! retcode = Lwt.catch (fun () -> @@ -432,6 +433,14 @@ let main (module C : M) ~select_commands = let parsed_config_file = parsed.Client_config.parsed_config_file and parsed_args = parsed.Client_config.parsed_args and config_commands = parsed.Client_config.config_commands in + let*! () = + Tezos_base_unix.Internal_event_unix.init_with_defaults + ?enable_default_daily_logs_at:C.default_daily_logs_path + ?internal_events: + (Option.bind parsed_config_file (fun cf -> + cf.Client_config.Cfg_file.internal_events)) + () + in let base_dir : string = match parsed.Client_config.base_dir with | Some p -> p diff --git a/src/lib_client_base_unix/client_main_run.mli b/src/lib_client_base_unix/client_main_run.mli index eb22cbd686d39b95566a18df5e91fb1acfd67d72..4d76a47f735b6e32c63954d2585e13bdf6d8af2d 100644 --- a/src/lib_client_base_unix/client_main_run.mli +++ b/src/lib_client_base_unix/client_main_run.mli @@ -52,6 +52,8 @@ sig define your own one. *) string + val default_daily_logs_path : string option + val default_media_type : Media_type.Command_line.t val other_registrations : diff --git a/src/lib_node_config/config_command.ml b/src/lib_node_config/config_command.ml index 9d973506c84a6643a7e2c6c73267f32d45cf0cc3..52819705acded4d110d0d274511d5051b90c71cb 100644 --- a/src/lib_node_config/config_command.ml +++ b/src/lib_node_config/config_command.ml @@ -29,7 +29,7 @@ let show (args : Shared_arg.t) = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in if not @@ Sys.file_exists args.config_file then Format.eprintf "@[@[Warning: no configuration file found at %s@,\ @@ -44,7 +44,7 @@ let show (args : Shared_arg.t) = let reset (args : Shared_arg.t) = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in if Sys.file_exists args.config_file then Format.eprintf "Ignoring previous configuration file: %s.@." @@ -64,7 +64,7 @@ let reset (args : Shared_arg.t) = let init (args : Shared_arg.t) = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in if Sys.file_exists args.config_file then failwith "Pre-existing configuration file at %s, use `reset`." @@ -95,7 +95,7 @@ let init (args : Shared_arg.t) = let update (args : Shared_arg.t) = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in if not (Sys.file_exists args.config_file) then failwith "Missing configuration file at %s. Use `%s config init [options]` to \ @@ -112,7 +112,7 @@ let update (args : Shared_arg.t) = let validate (args : Shared_arg.t) = let run = let open Lwt_result_syntax in - let*! () = Log_config.init_internal_events_with_defaults () in + let*! () = Tezos_base_unix.Internal_event_unix.init_with_defaults () in if not (Sys.file_exists args.config_file) then Format.eprintf "@[@[Warning: no configuration file found at %s@,\ diff --git a/src/lib_node_config/config_file.ml b/src/lib_node_config/config_file.ml index 3628c1a537ef34db609f455c78732c36027f939b..1cde96de6034e261da0fd7a6f5720d9c381bb46b 100644 --- a/src/lib_node_config/config_file.ml +++ b/src/lib_node_config/config_file.ml @@ -346,7 +346,7 @@ type t = { p2p : p2p; rpc : rpc; log : Lwt_log_sink_unix.cfg; - internal_events : Internal_event_config.t; + internal_events : Internal_event_config.t option; shell : Shell_limits.limits; blockchain_network : blockchain_network; metrics_addr : string list; @@ -405,13 +405,19 @@ let default_rpc = let default_disable_config_validation = false +let lwt_log_sink_default_cfg = + { + Lwt_log_sink_unix.default_cfg with + template = "$(date).$(milliseconds): $(message)"; + } + let default_config = { data_dir = default_data_dir; p2p = default_p2p; rpc = default_rpc; - log = Log_config.lwt_log_sink_default_cfg; - internal_events = Internal_event_config.empty; + log = lwt_log_sink_default_cfg; + internal_events = None; shell = Shell_limits.default_limits; blockchain_network = blockchain_network_mainnet; disable_config_validation = default_disable_config_validation; @@ -713,12 +719,11 @@ let encoding = ~description: "Configuration of the Lwt-log sink (part of the logging framework)" Lwt_log_sink_unix.cfg_encoding - Log_config.lwt_log_sink_default_cfg) - (dft + lwt_log_sink_default_cfg) + (opt "internal-events" ~description:"Configuration of the structured logging framework" - Internal_event_config.encoding - Internal_event_config.empty) + Internal_event_config.encoding) (dft "shell" ~description:"Configuration of network parameters" diff --git a/src/lib_node_config/config_file.mli b/src/lib_node_config/config_file.mli index 64f8c1d5315ecbddb5b21f11a16fb72eb6de08dd..c239ce211efed403f13e34ceafe139c6d5f6e3c5 100644 --- a/src/lib_node_config/config_file.mli +++ b/src/lib_node_config/config_file.mli @@ -52,7 +52,7 @@ type t = { p2p : p2p; rpc : rpc; log : Lwt_log_sink_unix.cfg; - internal_events : Tezos_base.Internal_event_config.t; + internal_events : Tezos_base.Internal_event_config.t option; shell : Shell_limits.limits; blockchain_network : blockchain_network; metrics_addr : string list; diff --git a/src/lib_node_config/dune b/src/lib_node_config/dune index df6565210035f8f7f313d49909765b8626ce56ac..b2ad38fcae2d8cf2f304a8731220bd1970f57c38 100644 --- a/src/lib_node_config/dune +++ b/src/lib_node_config/dune @@ -7,6 +7,7 @@ (instrumentation (backend bisect_ppx)) (libraries tezos-base + tezos-base.unix tezos-stdlib-unix tezos-shell-services tezos-rpc-http @@ -18,6 +19,7 @@ (:standard) -open Tezos_base.TzPervasives -open Tezos_base + -open Tezos_base_unix -open Tezos_stdlib_unix -open Tezos_shell_services -open Tezos_rpc_http diff --git a/src/lib_node_config/log_config.ml b/src/lib_node_config/log_config.ml deleted file mode 100644 index 2e85a41c13008ecccf1fd14383679e87016ef6a3..0000000000000000000000000000000000000000 --- a/src/lib_node_config/log_config.ml +++ /dev/null @@ -1,76 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2019-2023 Nomadic Labs, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -open Filename.Infix - -let lwt_log_sink_default_cfg = - { - Lwt_log_sink_unix.default_cfg with - template = "$(date).$(milliseconds): $(message)"; - } - -let make_default_internal_events ~data_dir = - (* By default the node has two logs output: - - on stdout using Lwt_log using the configured verbosity - - on disk, with a 7 days rotation with an info verbosity level *) - Internal_event_config.make_custom - [ - Uri.make ~scheme:Internal_event.Lwt_log_sink.uri_scheme (); - Uri.make - ~scheme:"file-descriptor-path" - ~path:(data_dir // "daily-logs" // "daily.log") - ~query: - [ - ("create-dirs", ["true"]); - ("daily-logs", ["7"]); - ("section-prefix", [":info"]); - ("format", ["pp"]); - ] - (); - ] - -let make_internal_events_with_defaults ?internal_events ?verbosity - ?(log_cfg = lwt_log_sink_default_cfg) () = - let log_cfg = - match verbosity with - | None -> log_cfg - | Some default_level -> {log_cfg with Lwt_log_sink_unix.default_level} - in - let internal_events = - match internal_events with - | None -> Internal_event_config.lwt_log - | Some (internal_events, data_dir) -> - if Internal_event_config.(is_empty internal_events) then - make_default_internal_events ~data_dir - else internal_events - in - (log_cfg, internal_events) - -let init_internal_events_with_defaults ?internal_events ?verbosity - ?(log_cfg = lwt_log_sink_default_cfg) () = - let lwt_log_sink, configuration = - make_internal_events_with_defaults ?internal_events ?verbosity ~log_cfg () - in - Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ~configuration () diff --git a/src/lib_node_config/log_config.mli b/src/lib_node_config/log_config.mli deleted file mode 100644 index acd1b1548f271c12818d6234a16a656456fa2af9..0000000000000000000000000000000000000000 --- a/src/lib_node_config/log_config.mli +++ /dev/null @@ -1,47 +0,0 @@ -(*****************************************************************************) -(* *) -(* Open Source License *) -(* Copyright (c) 2019-2023 Nomadic Labs, *) -(* *) -(* 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. *) -(* *) -(*****************************************************************************) - -(** This module handles default configuration for logs specific to the node *) - -(** Default value for the lwt_log sink *) -val lwt_log_sink_default_cfg : Lwt_log_sink_unix.cfg - -(** Creates internal event configuration using default node values depending on -parameters *) -val make_internal_events_with_defaults : - ?internal_events:Internal_event_config.t * string -> - ?verbosity:Internal_event.level -> - ?log_cfg:Lwt_log_sink_unix.cfg -> - unit -> - Lwt_log_sink_unix.cfg * Internal_event_config.t - -(** Inits internal event configuration using default node values depending on -parameters *) -val init_internal_events_with_defaults : - ?internal_events:Internal_event_config.t * string -> - ?verbosity:Internal_event.level -> - ?log_cfg:Lwt_log_sink_unix.cfg -> - unit -> - unit Lwt.t diff --git a/src/lib_p2p/test/test_p2p_broadcast.ml b/src/lib_p2p/test/test_p2p_broadcast.ml index 4a9d8d2199e44bda3c9dbc7590260c9368425581..f924b46edc0c63a3e9b7c3cc9d38bb99694acb03 100644 --- a/src/lib_p2p/test/test_p2p_broadcast.ml +++ b/src/lib_p2p/test/test_p2p_broadcast.ml @@ -49,13 +49,13 @@ let nb_oph = 1000 let no_check = false let init_logs = - let lwt_log_sink = + let log_cfg = Some (Lwt_log_sink_unix.create_cfg ~rules:"test.p2p.connection-pool -> info; p2p.connection-pool -> info" ()) in - lazy (Tezos_base_unix.Internal_event_unix.init ?lwt_log_sink ()) + lazy (Tezos_base_unix.Internal_event_unix.init ?log_cfg ()) let points = ref [] diff --git a/src/lib_p2p/test/test_p2p_logging.ml b/src/lib_p2p/test/test_p2p_logging.ml index ccc5edc18e1632da3d81c34f7492dc312ddbcd15..6569e8161ba7c0c7df851c189d1d72570d127298 100644 --- a/src/lib_p2p/test/test_p2p_logging.ml +++ b/src/lib_p2p/test/test_p2p_logging.ml @@ -324,13 +324,13 @@ module P2p_net = struct Lwt_result.return () end -let lwt_log_sink = Lwt_log_sink_unix.create_cfg ~rules:"* -> debug" () +let log_cfg = Lwt_log_sink_unix.create_cfg ~rules:"* -> debug" () let testcase (module T : TEST) = let addr = Node.default_ipv6_addr in Alcotest_lwt.test_case T.name `Quick (fun _switch () -> let open Lwt_syntax in - let* () = Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink () in + let* () = Tezos_base_unix.Internal_event_unix.init ~log_cfg () in Tztest.with_empty_mock_sink (fun () -> let* r = T.run ~addr () in match r with diff --git a/src/lib_p2p/test/test_p2p_maintenance.ml b/src/lib_p2p/test/test_p2p_maintenance.ml index 479ee1fc4aca029808205ed5d0f7087fa55b05f2..984c7c5fee85226112a6b1e6ef9d53639ef5ce2a 100644 --- a/src/lib_p2p/test/test_p2p_maintenance.ml +++ b/src/lib_p2p/test/test_p2p_maintenance.ml @@ -517,7 +517,7 @@ let wrap addr n f = aux n f) let main () = - let lwt_log_sink = + let log_cfg = Lwt_log_sink_unix.create_cfg ~rules: "test.p2p.maintenance -> debug; p2p.maintenance -> debug; \ @@ -525,7 +525,7 @@ let main () = () in let () = - Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) + Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~log_cfg ()) in let addr = Node.default_ipv6_addr in Lwt_main.run diff --git a/src/lib_p2p/test/test_p2p_node.ml b/src/lib_p2p/test/test_p2p_node.ml index b39763bae6090aac6c10326e281fee112ebc42da..950b26b1131bdc5b2a50d47def97d1e1c7396e66 100644 --- a/src/lib_p2p/test/test_p2p_node.ml +++ b/src/lib_p2p/test/test_p2p_node.ml @@ -99,10 +99,10 @@ let wrap addr n f = let main () = let () = - let lwt_log_sink = + let log_cfg = Lwt_log_sink_unix.create_cfg ~rules:"test.p2p.node -> info;" () in - Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) + Lwt_main.run (Tezos_base_unix.Internal_event_unix.init ~log_cfg ()) in let addr = Node.default_ipv6_addr in Lwt_main.run diff --git a/src/lib_p2p/test/test_p2p_pool.ml b/src/lib_p2p/test/test_p2p_pool.ml index d4d5fe5d909fdf6c74aad751c9aecf0a42b9a08a..1b8c8937c100db685713bba3ca4e01520ef2e3d3 100644 --- a/src/lib_p2p/test/test_p2p_pool.ml +++ b/src/lib_p2p/test/test_p2p_pool.ml @@ -719,12 +719,12 @@ end let () = Random.self_init () let init_logs = - let lwt_log_sink = + let log_cfg = Lwt_log_sink_unix.create_cfg ~rules:"test.p2p.connection-pool -> info; p2p.connection-pool -> info" () in - lazy (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) + lazy (Tezos_base_unix.Internal_event_unix.init ~log_cfg ()) let points = ref [] diff --git a/src/lib_p2p/test/test_p2p_socket.ml b/src/lib_p2p/test/test_p2p_socket.ml index 81de4c941ab4f30b80aa063d0a3c2909e4d3ece3..e895f823920607a99c5cd3b745c68d6d96f9bf42 100644 --- a/src/lib_p2p/test/test_p2p_socket.ml +++ b/src/lib_p2p/test/test_p2p_socket.ml @@ -513,12 +513,12 @@ module Garbled_data = struct end let init_logs = - let lwt_log_sink = + let log_cfg = Lwt_log_sink_unix.create_cfg ~rules:"test.p2p.connection -> info; p2p.connection -> info" () in - lazy (Tezos_base_unix.Internal_event_unix.init ~lwt_log_sink ()) + lazy (Tezos_base_unix.Internal_event_unix.init ~log_cfg ()) let wrap n f = let addr = Node.default_ipv6_addr in diff --git a/src/lib_validation/external_validator.ml b/src/lib_validation/external_validator.ml index 54ed42f7b4caafce76cbcd3f74b6bc082df15002..0f973805f0f9f843ca1f67203d55806495e392f1 100644 --- a/src/lib_validation/external_validator.ml +++ b/src/lib_validation/external_validator.ml @@ -257,8 +257,8 @@ let run ~readonly ~using_std_channel input output = if using_std_channel then Lwt.return_unit else Tezos_base_unix.Internal_event_unix.init - ~configuration:log_config.internal_events - ~lwt_log_sink:log_config.lwt_log_sink_unix + ~internal_events:log_config.internal_events + ~log_cfg:log_config.lwt_log_sink_unix () in (* Main loop waiting for request to be processed, forever, until the