Skip to content

Commit

Permalink
add option --quiet for suppressing all the logs for ordinary scenar…
Browse files Browse the repository at this point in the history
…ios (2)
  • Loading branch information
gfngfn committed Sep 8, 2024
1 parent 0c5513e commit 160ccb9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
18 changes: 14 additions & 4 deletions src/backend/buildDocument.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ let transform_text =
EvalUtil.get_string


let output_pdf (abspath_out : abs_path) (pdfret : HandlePdf.t) : (unit, config_error) result =
let output_pdf (display_config : Logging.config) (abspath_out : abs_path) (pdfret : HandlePdf.t) : (unit, config_error) result =
let open ResultMonad in
try
HandlePdf.write_to_file abspath_out pdfret;
HandlePdf.write_to_file display_config abspath_out pdfret;
return ()
with
| _ -> err @@ CannotOutputResult{ path = abspath_out; message = "HandlePdf.write_to_file failed" }
Expand Down Expand Up @@ -149,7 +149,17 @@ let build_document ~(max_repeats : int) (transform : syntactic_value -> 'a) (res
let main (output_mode : output_mode) (pdf_config : HandlePdf.config) ~(page_number_limit : int) ~(max_repeats : int) (display_config : Logging.config) =
match output_mode with
| PdfMode ->
build_document ~max_repeats (transform_pdf display_config pdf_config ~page_number_limit) reset_pdf output_pdf display_config
build_document
~max_repeats
(transform_pdf display_config pdf_config ~page_number_limit)
reset_pdf
(output_pdf display_config)
display_config

| TextMode(_) ->
build_document ~max_repeats transform_text Fun.id output_text display_config
build_document
~max_repeats
transform_text
Fun.id
output_text
display_config
6 changes: 3 additions & 3 deletions src/backend/handlePdf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ let create_empty_pdf () : t =
PDF(pdf, Alist.empty)


let write_to_file (abspath : abs_path) ((PDF(pdf, pageacc)) : t) : unit =
Logging.begin_to_embed_fonts ();
let write_to_file (display_config : Logging.config) (abspath : abs_path) ((PDF(pdf, pageacc)) : t) : unit =
Logging.begin_to_embed_fonts display_config;
let pdfdict_font = FontInfo.get_font_dictionary pdf in
let pdfarr_procset =
Pdf.Array(List.map (fun s -> Pdf.Name(s))
Expand All @@ -518,7 +518,7 @@ let write_to_file (abspath : abs_path) ((PDF(pdf, pageacc)) : t) : unit =
("/ProcSet", pdfarr_procset);
])
in
Logging.begin_to_write_page ();
Logging.begin_to_write_page display_config;
let pagelst =
pageacc |> Alist.to_list |> List.map (fun page ->
{ page with Pdfpage.resources = Pdf.Indirect(ir_resources); }
Expand Down
2 changes: 1 addition & 1 deletion src/backend/handlePdf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type page

val write_page : config -> page -> page_parts_scheme_func -> t -> t

val write_to_file : abs_path -> t -> unit
val write_to_file : Logging.config -> abs_path -> t -> unit

val make_empty_page : paper_size:(length * length) -> page_break_info -> page_content_scheme -> page

Expand Down
16 changes: 10 additions & 6 deletions src/frontend/logging.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ let deps_config_file (config : config) (abspath_deps_config : abs_path) =
end


let begin_to_embed_fonts () =
print_endline " ---- ---- ---- ----";
print_endline " embedding fonts ..."
let begin_to_embed_fonts (config : config) =
if is_not_quiet config.verbosity then begin
print_endline " ---- ---- ---- ----";
print_endline " embedding fonts ..."
end


let begin_to_write_page () =
print_endline " ---- ---- ---- ----";
print_endline " writing pages ..."
let begin_to_write_page (config : config) =
if is_not_quiet config.verbosity then begin
print_endline " ---- ---- ---- ----";
print_endline " writing pages ..."
end


let warn_cmyk_image (file_name : abs_path) =
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/logging.mli
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ val dump_file : config -> already_exists:bool -> abs_path -> unit

val deps_config_file : config -> abs_path -> unit

val begin_to_embed_fonts : unit -> unit
val begin_to_embed_fonts : config -> unit

val begin_to_write_page : unit -> unit
val begin_to_write_page : config -> unit

val warn_noninjective_cmap : Uchar.t -> Uchar.t -> Otfed.Value.glyph_id -> unit

Expand Down

0 comments on commit 160ccb9

Please sign in to comment.