Skip to content

Commit 2cd5ff9

Browse files
authored
refactor logging from multiline to formatted json (#154)
* refactor logging from multiline to formatted json * regenerate api * regenerate api
1 parent 043a1e6 commit 2cd5ff9

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.32-dev0
2+
3+
* Improve logging of params to single line json
4+
15
## 0.0.31
26

37
* Support model name as api parameter

pipeline-notebooks/pipeline-general.ipynb

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -737,19 +737,22 @@
737737
" file_content_type=None,\n",
738738
" response_type=\"application/json\"\n",
739739
"):\n",
740-
" logger.debug(\n",
741-
" f\"\\npipeline_api input params:\\n\"\n",
742-
" f\"filename: {filename}\\n\"\n",
743-
" f\"m_strategy: {m_strategy}\\n\"\n",
744-
" f\"m_coordinates: {m_coordinates}\\n\"\n",
745-
" f\"m_ocr_languages: {m_ocr_languages}\\n\"\n",
746-
" f\"m_encoding: {m_encoding}\\n\"\n",
747-
" f\"m_xml_keep_tags: {m_xml_keep_tags}\\n\"\n",
748-
" f\"m_pdf_infer_table_structure: {m_pdf_infer_table_structure}\\n\"\n",
749-
" f\"m_hi_res_model_name: {m_hi_res_model_name}\\n\"\n",
750-
" f\"file_content_type: {file_content_type}\\n\"\n",
751-
" f\"response_type: {response_type}\"\n",
740+
" logger.debug(\"pipeline_api input params: {}\".format(\n",
741+
" json.dumps({\n",
742+
" \"request\": request,\n",
743+
" \"filename\": filename,\n",
744+
" \"m_strategy\": m_strategy,\n",
745+
" \"m_coordinates\": m_coordinates,\n",
746+
" \"m_ocr_languages\": m_ocr_languages,\n",
747+
" \"m_encoding\": m_encoding,\n",
748+
" \"m_xml_keep_tags\": m_xml_keep_tags,\n",
749+
" \"m_pdf_infer_table_structure\": m_pdf_infer_table_structure,\n",
750+
" \"m_hi_res_model_name\": m_hi_res_model_name,\n",
751+
" \"file_content_type\": file_content_type,\n",
752+
" \"response_type\": response_type\n",
753+
" }, default=str\n",
752754
" )\n",
755+
" ))\n",
753756
" if filename.endswith(\".msg\"):\n",
754757
" # Note(yuming): convert file type for msg files\n",
755758
" # since fast api might sent the wrong one.\n",
@@ -791,17 +794,18 @@
791794
" pdf_infer_table_structure = False\n",
792795
" \n",
793796
" try:\n",
794-
" logger.debug(\n",
795-
" f\"\\npartition input data:\\n\"\n",
796-
" f\"content_type: {file_content_type}\\n\"\n",
797-
" f\"strategy: {strategy}\\n\"\n",
798-
" f\"ocr_languages: {ocr_languages}\\n\"\n",
799-
" f\"coordinates: {show_coordinates}\\n\"\n",
800-
" f\"pdf_infer_table_structure: {pdf_infer_table_structure}\\n\"\n",
801-
" f\"encoding: {encoding}\\n\"\n",
802-
" f\"model_name: {hi_res_model_name}\\n\"\n",
803-
" f\"xml_keep_tags: {xml_keep_tags}\\n\"\n",
804-
" )\n",
797+
" logger.debug(\"partition input data: {}\".format(\n",
798+
" json.dumps({\n",
799+
" \"content_type\": file_content_type,\n",
800+
" \"strategy\": strategy,\n",
801+
" \"ocr_languages\": ocr_languages,\n",
802+
" \"coordinates\": show_coordinates,\n",
803+
" \"pdf_infer_table_structure\": pdf_infer_table_structure,\n",
804+
" \"encoding\": encoding,\n",
805+
" \"model_name\": hi_res_model_name,\n",
806+
" \"xml_keep_tags\": xml_keep_tags\n",
807+
" }, default=str)\n",
808+
" ))\n",
805809
" \n",
806810
" if file_content_type == \"application/pdf\" and pdf_parallel_mode_enabled:\n",
807811
" elements = partition_pdf_splits(\n",

prepline_general/api/general.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,24 @@ def pipeline_api(
210210
response_type="application/json",
211211
):
212212
logger.debug(
213-
f"\npipeline_api input params:\n"
214-
f"filename: {filename}\n"
215-
f"m_strategy: {m_strategy}\n"
216-
f"m_coordinates: {m_coordinates}\n"
217-
f"m_ocr_languages: {m_ocr_languages}\n"
218-
f"m_encoding: {m_encoding}\n"
219-
f"m_xml_keep_tags: {m_xml_keep_tags}\n"
220-
f"m_pdf_infer_table_structure: {m_pdf_infer_table_structure}\n"
221-
f"m_hi_res_model_name: {m_hi_res_model_name}\n"
222-
f"file_content_type: {file_content_type}\n"
223-
f"response_type: {response_type}"
213+
"pipeline_api input params: {}".format(
214+
json.dumps(
215+
{
216+
"request": request,
217+
"filename": filename,
218+
"m_strategy": m_strategy,
219+
"m_coordinates": m_coordinates,
220+
"m_ocr_languages": m_ocr_languages,
221+
"m_encoding": m_encoding,
222+
"m_xml_keep_tags": m_xml_keep_tags,
223+
"m_pdf_infer_table_structure": m_pdf_infer_table_structure,
224+
"m_hi_res_model_name": m_hi_res_model_name,
225+
"file_content_type": file_content_type,
226+
"response_type": response_type,
227+
},
228+
default=str,
229+
)
230+
)
224231
)
225232
if filename.endswith(".msg"):
226233
# Note(yuming): convert file type for msg files
@@ -266,15 +273,21 @@ def pipeline_api(
266273

267274
try:
268275
logger.debug(
269-
f"\npartition input data:\n"
270-
f"content_type: {file_content_type}\n"
271-
f"strategy: {strategy}\n"
272-
f"ocr_languages: {ocr_languages}\n"
273-
f"coordinates: {show_coordinates}\n"
274-
f"pdf_infer_table_structure: {pdf_infer_table_structure}\n"
275-
f"encoding: {encoding}\n"
276-
f"model_name: {hi_res_model_name}\n"
277-
f"xml_keep_tags: {xml_keep_tags}\n"
276+
"partition input data: {}".format(
277+
json.dumps(
278+
{
279+
"content_type": file_content_type,
280+
"strategy": strategy,
281+
"ocr_languages": ocr_languages,
282+
"coordinates": show_coordinates,
283+
"pdf_infer_table_structure": pdf_infer_table_structure,
284+
"encoding": encoding,
285+
"model_name": hi_res_model_name,
286+
"xml_keep_tags": xml_keep_tags,
287+
},
288+
default=str,
289+
)
290+
)
278291
)
279292

280293
if file_content_type == "application/pdf" and pdf_parallel_mode_enabled:
@@ -445,7 +458,7 @@ def return_content_type(filename):
445458

446459

447460
@router.post("/general/v0/general")
448-
@router.post("/general/v0.0.31/general")
461+
@router.post("/general/v0.0.32/general")
449462
def pipeline_1(
450463
request: Request,
451464
gz_uncompressed_content_type: Optional[str] = Form(default=None),

preprocessing-pipeline-family.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name: general
2-
version: 0.0.31
2+
version: 0.0.32

0 commit comments

Comments
 (0)