diff --git a/src/bin_agnostic_baker/main_agnostic_baker.ml b/src/bin_agnostic_baker/main_agnostic_baker.ml index bf54a314256e4fd4c670e86112b49eff87620048..a1c5132671f86849762de99af4812bbabb2d77ab 100644 --- a/src/bin_agnostic_baker/main_agnostic_baker.ml +++ b/src/bin_agnostic_baker/main_agnostic_baker.ml @@ -40,4 +40,5 @@ let () = in Format.pp_print_flush Format.err_formatter () ; Format.pp_print_flush Format.std_formatter () ; + let*! () = Tezos_base_unix.Internal_event_unix.close () in Lwt.return retcode)) diff --git a/src/lib_agnostic_baker/daemon.ml b/src/lib_agnostic_baker/daemon.ml index 943ad04f62190cbb94f3e2dadf9b3ea0de4206f2..13900981762543e630c19a9fcafac382e44ff400 100644 --- a/src/lib_agnostic_baker/daemon.ml +++ b/src/lib_agnostic_baker/daemon.ml @@ -52,6 +52,8 @@ let run_thread ~protocol_hash ~baker_commands ~baker_args ~cancel_promise (module Config) ~select_commands ~cmd_args:baker_args + (* The underlying logging from the baker must not be initialised, otherwise we double log. *) + ~disable_logging:true (); cancel_promise; ] @@ -77,9 +79,6 @@ let spawn_baker protocol_hash ~baker_args = let cancel_promise, canceller = Lwt.wait () in let* thread = let*? plugin = Protocol_plugins.proto_plugin_for_protocol protocol_hash in - (* The internal event logging needs to be closed, because another one will be - initialised in the [run_baker_binary]. *) - let*! () = Tezos_base_unix.Internal_event_unix.close () in let baker_commands = Commands.baker_commands plugin in return @@ run_thread diff --git a/src/lib_client_base_unix/client_main_run.ml b/src/lib_client_base_unix/client_main_run.ml index 10c978f33d2be0367c3bd998bfd3db724cd64306..769039ba3a1b284d1a74b7e3f97368d8cc2b5ee3 100644 --- a/src/lib_client_base_unix/client_main_run.ml +++ b/src/lib_client_base_unix/client_main_run.ml @@ -418,7 +418,8 @@ let warn_if_argv0_name_not_octez () = executable_name (* Main (lwt) entry *) -let main (module C : M) ~select_commands ?cmd_args () = +let main (module C : M) ~select_commands ?cmd_args ?(disable_logging = false) () + = let open Lwt_result_syntax in let global_options = C.global_options () in let executable_name = Filename.basename Sys.executable_name in @@ -475,36 +476,39 @@ let main (module C : M) ~select_commands ?cmd_args () = | None -> C.default_base_dir | Some p -> p.Client_config.Cfg_file.base_dir) in - let daily_logs_path = - C.default_daily_logs_path - |> Option.map - Filename.Infix.(fun logdir -> base_dir // "logs" // logdir) - in let require_auth = parsed.Client_config.require_auth in let*! () = - let open Tezos_base_unix.Internal_event_unix in - (* Update config with color logging switch *) - let log_cfg = - match parsed_args with - | None -> Tezos_base_unix.Logs_simple_config.default_cfg - | Some parsed_args -> - { - Tezos_base_unix.Logs_simple_config.default_cfg with - colors = Option.value parsed_args.log_coloring ~default:true; - } - in - let config = - make_with_defaults - ?enable_default_daily_logs_at:daily_logs_path - ~log_cfg - () - in - match parsed_config_file with - | None -> init ~config () - | Some cf -> ( - match cf.Client_config.Cfg_file.internal_events with - | None -> init ~config () - | Some config -> init ~config ()) + if disable_logging then Lwt.return_unit + else + let open Tezos_base_unix.Internal_event_unix in + let daily_logs_path = + C.default_daily_logs_path + |> Option.map + Filename.Infix.(fun logdir -> base_dir // "logs" // logdir) + in + (* Update config with color logging switch *) + let log_cfg = + match parsed_args with + | None -> Tezos_base_unix.Logs_simple_config.default_cfg + | Some parsed_args -> + { + Tezos_base_unix.Logs_simple_config.default_cfg with + colors = + Option.value parsed_args.log_coloring ~default:true; + } + in + let config = + make_with_defaults + ?enable_default_daily_logs_at:daily_logs_path + ~log_cfg + () + in + match parsed_config_file with + | None -> init ~config () + | Some cf -> ( + match cf.Client_config.Cfg_file.internal_events with + | None -> init ~config () + | Some config -> init ~config ()) in let rpc_config = let rpc_config : RPC_client_unix.config = @@ -633,7 +637,10 @@ let main (module C : M) ~select_commands ?cmd_args () = in Format.pp_print_flush Format.err_formatter () ; Format.pp_print_flush Format.std_formatter () ; - let*! () = Tezos_base_unix.Internal_event_unix.close () in + let*! () = + if disable_logging then Lwt.return_unit + else Tezos_base_unix.Internal_event_unix.close () + in Lwt.return retcode (* Where all the user friendliness starts *) @@ -650,7 +657,8 @@ let lwt_run (module M : M) ~(select_commands : RPC_client_unix.http_ctxt -> Client_config.cli_args -> - Client_context.full Tezos_clic.command list tzresult Lwt.t) ?cmd_args () - = + Client_context.full Tezos_clic.command list tzresult Lwt.t) ?cmd_args + ?disable_logging () = Lwt.Exception_filter.(set handle_all_except_runtime) ; - Lwt_exit.wrap_and_forward @@ main (module M) ~select_commands ?cmd_args () + Lwt_exit.wrap_and_forward + @@ main (module M) ~select_commands ?cmd_args ?disable_logging () diff --git a/src/lib_client_base_unix/client_main_run.mli b/src/lib_client_base_unix/client_main_run.mli index 331502341b35f9332990d8d36eeb2c2f364d8375..3019d95eb51c468f23a81e127550f9547ceba78e 100644 --- a/src/lib_client_base_unix/client_main_run.mli +++ b/src/lib_client_base_unix/client_main_run.mli @@ -104,7 +104,9 @@ val run : application computation as an Lwt promise. Unlike [run], this function does not run the event loop, it merely returns the wrapped promise to be integrated into an existing Lwt-based application. It can optionally use - [?cmd_args] as already parsed arguments to the [main] function. *) + [?cmd_args] as already parsed arguments to the [main] function. It can + also optionally disable logging of the underlying process via + [?disable_logging]. *) val lwt_run : (module M) -> select_commands: @@ -112,5 +114,6 @@ val lwt_run : Client_config.cli_args -> Client_context.full Tezos_clic.command list tzresult Lwt.t) -> ?cmd_args:string list -> + ?disable_logging:bool -> unit -> int Lwt.t