Revert "feat: wkhtmltopdf logging (#19935)"
This reverts commit 6354a018de.
This commit is contained in:
parent
6e046a9752
commit
b0c2f56dae
2 changed files with 2 additions and 38 deletions
|
|
@ -1,8 +1,6 @@
|
|||
# imports - standard imports
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from copy import deepcopy
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from typing import Literal
|
||||
|
|
@ -126,29 +124,3 @@ def sanitized_dict(form_dict):
|
|||
if secret_kw in k:
|
||||
sanitized_dict[k] = "********"
|
||||
return sanitized_dict
|
||||
|
||||
|
||||
@contextmanager
|
||||
def pipe_to_log(logger_fn, stream=None):
|
||||
"Pass an existing logger function e.g. logger.info. Stream defaults to stdout"
|
||||
# late bind source
|
||||
if stream is None:
|
||||
stream = sys.stdout
|
||||
|
||||
stream_int = stream.fileno()
|
||||
r_int, w_int = os.pipe()
|
||||
|
||||
# copy stream_fd before it is overwritten
|
||||
with os.fdopen(os.dup(stream_int), "wb") as copied:
|
||||
stream.flush()
|
||||
os.dup2(w_int, stream_int) # $ exec >&pipe
|
||||
try:
|
||||
with os.fdopen(w_int, "wb"):
|
||||
yield stream
|
||||
finally:
|
||||
# restore stream to its previous value
|
||||
stream.flush()
|
||||
os.dup2(copied.fileno(), stream_int) # $ exec >&copied
|
||||
with os.fdopen(r_int, newline="") as r:
|
||||
text = r.read()
|
||||
logger_fn(text)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import frappe
|
|||
from frappe import _
|
||||
from frappe.utils import scrub_urls
|
||||
from frappe.utils.jinja_globals import bundled_asset, is_rtl
|
||||
from frappe.utils.logger import pipe_to_log
|
||||
|
||||
PDF_CONTENT_ERRORS = [
|
||||
"ContentNotFoundError",
|
||||
|
|
@ -24,9 +23,6 @@ PDF_CONTENT_ERRORS = [
|
|||
"RemoteHostClosedError",
|
||||
]
|
||||
|
||||
logger = frappe.logger("wkhtmltopdf", max_size=100000, file_count=3)
|
||||
logger.setLevel("INFO")
|
||||
|
||||
|
||||
def pdf_header_html(soup, head, content, styles, html_id, css):
|
||||
return frappe.render_template(
|
||||
|
|
@ -87,13 +83,8 @@ def get_pdf(html, options=None, output: PdfWriter | None = None):
|
|||
options.update({"disable-smart-shrinking": ""})
|
||||
|
||||
try:
|
||||
# wkhtmltopdf writes the pdf to stdout and errors to stderr
|
||||
# pdfkit v1.0.0 writes the pdf to file or returns it
|
||||
# stderr is written to sys.stdout if verbose=True is supplied
|
||||
# Set filename property to false, so no file is actually created
|
||||
# defaults to redirecting stdout
|
||||
with pipe_to_log(logger.info):
|
||||
filedata = pdfkit.from_string(html, False, options=options or {}, verbose=True)
|
||||
filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
|
||||
|
||||
# create in-memory binary streams from filedata and create a PdfReader object
|
||||
reader = PdfReader(io.BytesIO(filedata))
|
||||
|
|
@ -151,6 +142,7 @@ def prepare_options(html, options):
|
|||
"print-media-type": None,
|
||||
"background": None,
|
||||
"images": None,
|
||||
"quiet": None,
|
||||
# 'no-outline': None,
|
||||
"encoding": "UTF-8",
|
||||
# 'load-error-handling': 'ignore'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue