diff --git a/src/lib_client_base_unix/client_main_run.ml b/src/lib_client_base_unix/client_main_run.ml index cea5cdf28..af3963ff5 100644 --- a/src/lib_client_base_unix/client_main_run.ml +++ b/src/lib_client_base_unix/client_main_run.ml @@ -25,6 +25,34 @@ let builtin_commands = return ()) ; ] +(* Duplicated from the node, here for now since the client still + embeds the baker. To be moved where appropriate when the baker is + definitively moved/factorized in its own binary. *) +let find_log_rules () = + match Option.try_with (fun () -> Sys.getenv "TEZOS_LOG"), + Option.try_with (fun () -> Sys.getenv "LWT_LOG") + with + | Some rules, None -> "environment variable TEZOS_LOG", Some rules + | None, Some rules -> "environment variable LWT_LOG", Some rules + | None, None -> "default rules", None + | Some rules, Some _ -> + Format.eprintf + "@[@{@{Warning@}@} \ + Both environment variables TEZOS_LOG and LWT_LOG \ + defined, using TEZOS_LOG.@]@\n@." ; + "environment varible TEZOS_LOG", Some rules + +let init_logger () = + Lwt_log_core.add_rule "*" Lwt_log_core.Notice ; + let origin, rules = find_log_rules () in + Option.iter rules ~f:begin fun rules -> + try Lwt_log_core.load_rules rules ~fail_on_error:true + with _ -> + Pervasives.failwith + (Format.asprintf "Incorrect log rules defined in %s." origin) + end ; + Logging_unix.(init ~template:"$(message)" Stderr) + (* Main (lwt) entry *) let main select_commands = let executable_name = Filename.basename Sys.executable_name in @@ -45,6 +73,7 @@ let main select_commands = (if Unix.isatty Unix.stdout then Ansi else Plain) Short) ; ignore Cli_entries.(setup_formatter Format.err_formatter (if Unix.isatty Unix.stderr then Ansi else Plain) Short) ; + init_logger () >>= fun () -> Lwt.catch begin fun () -> begin Client_config.parse_config_args (new unix_full @@ -122,6 +151,7 @@ let main select_commands = end >>= fun retcode -> Format.pp_print_flush Format.err_formatter () ; Format.pp_print_flush Format.std_formatter () ; + Logging_unix.close () >>= fun () -> Lwt.return retcode (* Where all the user friendliness starts *)