Remove custom logger
This commit is contained in:
@@ -15,16 +15,12 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with OCRmyPDF. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
import sys
|
||||
import os
|
||||
from contextlib import suppress
|
||||
|
||||
ERROR = 40
|
||||
WARN = 30
|
||||
INFO = 20
|
||||
DEBUG = 10
|
||||
|
||||
|
||||
class PDFContext:
|
||||
"""Holds our context for a particular run of the pipeline"""
|
||||
@@ -78,63 +74,4 @@ def cleanup_working_files(work_folder, options):
|
||||
|
||||
|
||||
def get_logger(options=None, prefix=''):
|
||||
level = ERROR # TODO: add option
|
||||
if options is not None:
|
||||
if options.quiet or options.output_file == '-' or options.sidecar == '-':
|
||||
return NullLogger()
|
||||
if options.verbose == 0:
|
||||
level = ERROR
|
||||
elif options.verbose == 1:
|
||||
level = WARN
|
||||
elif options.verbose == 2:
|
||||
level = INFO
|
||||
elif options.verbose >= 3:
|
||||
level = DEBUG
|
||||
|
||||
return Logger(prefix, level)
|
||||
|
||||
|
||||
class Logger:
|
||||
def __init__(self, prefix, level=DEBUG):
|
||||
self.prefix = prefix
|
||||
self.level = level
|
||||
|
||||
def debug(self, *args, **kwargs):
|
||||
if self.level <= DEBUG:
|
||||
print('DEBUG', self.prefix, end='', file=sys.stderr)
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
def info(self, *args, **kwargs):
|
||||
if self.level <= INFO:
|
||||
print('INFO', self.prefix, end='', file=sys.stderr)
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
def warning(self, *args, **kwargs):
|
||||
self.warn(*args, **kwargs)
|
||||
|
||||
def warn(self, *args, **kwargs):
|
||||
if self.level <= WARN:
|
||||
print('WARN', self.prefix, end='', file=sys.stderr)
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
def error(self, *args, **kwargs):
|
||||
if self.level <= ERROR:
|
||||
print('ERROR', self.prefix, end='', file=sys.stderr)
|
||||
print(*args, file=sys.stderr)
|
||||
|
||||
|
||||
class NullLogger:
|
||||
def debug(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def info(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def warning(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def warn(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def error(self, *args, **kwargs):
|
||||
pass
|
||||
return logging.getLogger(prefix)
|
||||
|
||||
@@ -33,7 +33,11 @@ from subprocess import (
|
||||
from textwrap import dedent
|
||||
|
||||
from . import get_version
|
||||
from ..exceptions import MissingDependencyError, TesseractConfigError, SubprocessOutputError
|
||||
from ..exceptions import (
|
||||
MissingDependencyError,
|
||||
TesseractConfigError,
|
||||
SubprocessOutputError,
|
||||
)
|
||||
from ..helpers import page_number
|
||||
|
||||
OrientationConfidence = namedtuple('OrientationConfidence', ('angle', 'confidence'))
|
||||
@@ -342,7 +346,6 @@ def generate_pdf(
|
||||
# to the number of order parameters here
|
||||
|
||||
args_tesseract.extend([input_image, prefix, 'pdf', 'txt'] + tessconfig)
|
||||
|
||||
try:
|
||||
log.debug(args_tesseract)
|
||||
stdout = check_output(args_tesseract, stderr=STDOUT, timeout=timeout)
|
||||
|
||||
+1
-2
@@ -1014,8 +1014,7 @@ def test_bad_utf8(spoof_tess_bad_utf8, renderer, resources, no_outpdf):
|
||||
assert out == '', "stdout not clean"
|
||||
assert p.returncode != 0
|
||||
assert 'not utf-8' in err, "should whine about utf-8"
|
||||
# TODO: find out why this should be tested
|
||||
# assert '\\x96' in err, 'should repeat backslash encoded output'
|
||||
assert '\\x96' in err, 'should repeat backslash encoded output'
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
|
||||
Reference in New Issue
Block a user