mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-28 18:02:38 +02:00
Update the way we get debug logs
Move the logic for grabbing debug logs to a new place, now that we have merged the two conversion stages (doc to pixels, pixels to PDF).
This commit is contained in:
parent
e34c36f7bc
commit
f42bb23229
1 changed files with 12 additions and 13 deletions
|
@ -22,8 +22,6 @@ log = logging.getLogger(__name__)
|
||||||
MAX_CONVERSION_LOG_CHARS = 150 * 50 # up to ~150 lines of 50 characters
|
MAX_CONVERSION_LOG_CHARS = 150 * 50 # up to ~150 lines of 50 characters
|
||||||
DOC_TO_PIXELS_LOG_START = "----- DOC TO PIXELS LOG START -----"
|
DOC_TO_PIXELS_LOG_START = "----- DOC TO PIXELS LOG START -----"
|
||||||
DOC_TO_PIXELS_LOG_END = "----- DOC TO PIXELS LOG END -----"
|
DOC_TO_PIXELS_LOG_END = "----- DOC TO PIXELS LOG END -----"
|
||||||
PIXELS_TO_PDF_LOG_START = "----- PIXELS TO PDF LOG START -----"
|
|
||||||
PIXELS_TO_PDF_LOG_END = "----- PIXELS TO PDF LOG END -----"
|
|
||||||
|
|
||||||
TIMEOUT_EXCEPTION = 15
|
TIMEOUT_EXCEPTION = 15
|
||||||
TIMEOUT_GRACE = 15
|
TIMEOUT_GRACE = 15
|
||||||
|
@ -222,17 +220,6 @@ class IsolationProvider(ABC):
|
||||||
text = "Successfully converted document"
|
text = "Successfully converted document"
|
||||||
self.print_progress(document, False, text, 100)
|
self.print_progress(document, False, text, 100)
|
||||||
|
|
||||||
if getattr(sys, "dangerzone_dev", False):
|
|
||||||
assert p.stderr
|
|
||||||
debug_log = read_debug_text(p.stderr, MAX_CONVERSION_LOG_CHARS)
|
|
||||||
p.stderr.close()
|
|
||||||
log.info(
|
|
||||||
"Conversion output (doc to pixels)\n"
|
|
||||||
f"{DOC_TO_PIXELS_LOG_START}\n"
|
|
||||||
f"{debug_log}" # no need for an extra newline here
|
|
||||||
f"{DOC_TO_PIXELS_LOG_END}"
|
|
||||||
)
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def pixels_to_pdf(
|
def pixels_to_pdf(
|
||||||
self, document: Document, tempdir: str, ocr_lang: Optional[str]
|
self, document: Document, tempdir: str, ocr_lang: Optional[str]
|
||||||
|
@ -353,6 +340,18 @@ class IsolationProvider(ABC):
|
||||||
document, p, timeout_grace=timeout_grace, timeout_force=timeout_force
|
document, p, timeout_grace=timeout_grace, timeout_force=timeout_force
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Read the stderr of the process only if:
|
||||||
|
# * Dev mode is enabled.
|
||||||
|
# * The process has exited (else we risk hanging).
|
||||||
|
if getattr(sys, "dangerzone_dev", False) and p.poll() is not None:
|
||||||
|
assert p.stderr
|
||||||
|
debug_log = read_debug_text(p.stderr, MAX_CONVERSION_LOG_CHARS)
|
||||||
|
log.info(
|
||||||
|
"Conversion output (doc to pixels)\n"
|
||||||
|
f"{DOC_TO_PIXELS_LOG_START}\n"
|
||||||
|
f"{debug_log}" # no need for an extra newline here
|
||||||
|
f"{DOC_TO_PIXELS_LOG_END}"
|
||||||
|
)
|
||||||
|
|
||||||
# From global_common:
|
# From global_common:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue