Skip to content

Commit 6a8f6ab

Browse files
Fixed up logging and debugging (#326)
* Removed setting root loggers log level to debug * Added more debug calls * Tried to be nice and remove email, but turns out that breaks spectacularly
1 parent d62beec commit 6a8f6ab

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

pypandoc/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import Union
55
from typing import Generator
66

7-
import logging
87
import os
98
import re
109
import subprocess
@@ -14,12 +13,13 @@
1413
import glob
1514
from pathlib import Path
1615

17-
from .handler import _check_log_handler
16+
from .handler import logger, _check_log_handler
1817
from .pandoc_download import DEFAULT_TARGET_FOLDER, download_pandoc
1918
from .py3compat import cast_bytes, cast_unicode, string_types, url2path, urlparse
2019

2120
__author__ = u'Juho Vepsäläinen'
2221
__author_email__ = "bebraw@gmail.com"
22+
__maintainer__ = u'Jessica Tegner'
2323
__url__ = 'https://github.com/JessicaTegner/pypandoc'
2424
__version__ = '1.10'
2525
__license__ = 'MIT'
@@ -51,9 +51,6 @@
5151
'get_pandoc_formats', 'get_pandoc_version', 'get_pandoc_path',
5252
'download_pandoc']
5353

54-
# Set up the module level logger
55-
logger = logging.getLogger(__name__)
56-
5754
def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encoding:str='utf-8',
5855
outputfile:Union[None, str, Path]=None, filters:Union[Iterable, None]=None, verify_format:bool=True,
5956
sandbox:bool=False, cworkdir:Union[str, None]=None) -> str:
@@ -322,14 +319,18 @@ def _convert_input(source, format, input_type, to, extra_args=(),
322319
sandbox=False, cworkdir=None):
323320

324321
_check_log_handler()
322+
323+
logger.debug("Ensuring pandoc path...")
325324
_ensure_pandoc_path()
326325

327326
if verify_format:
327+
logger.debug("Verifying format...")
328328
format, to = _validate_formats(format, to, outputfile)
329329
else:
330330
format = normalize_format(format)
331331
to = normalize_format(to)
332332

333+
logger.debug("Identifying input type...")
333334
string_input = input_type == 'string'
334335
if not string_input:
335336
if isinstance(source, str):
@@ -351,7 +352,10 @@ def _convert_input(source, format, input_type, to, extra_args=(),
351352

352353
if sandbox:
353354
if ensure_pandoc_minimal_version(2,15): # sandbox was introduced in pandoc 2.15, so only add if we are using 2.15 or above.
355+
logger.debug("Adding sandbox argument...")
354356
args.append("--sandbox")
357+
else:
358+
logger.warning("Sandbox argument was used, but pandoc version is too low. Ignoring argument.")
355359

356360
args.extend(extra_args)
357361

@@ -373,6 +377,7 @@ def _convert_input(source, format, input_type, to, extra_args=(),
373377
if cworkdir and old_wd != cworkdir:
374378
os.chdir(cworkdir)
375379

380+
logger.debug("Running pandoc...")
376381
p = subprocess.Popen(
377382
args,
378383
stdin=subprocess.PIPE if string_input else None,
@@ -702,7 +707,7 @@ def _ensure_pandoc_path() -> None:
702707
# path exist but is not useable -> not executable?
703708
log_msg = ("Found {}, but not using it because of an "
704709
"error:".format(path))
705-
logging.exception(log_msg)
710+
logger.exception(log_msg)
706711
continue
707712
version = [int(x) for x in version_string.split(".")]
708713
while len(version) < len(curr_version):

pypandoc/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
import logging
33

4-
logger = logging.getLogger(__name__.split('.')[0])
4+
logger = logging.getLogger(__name__.split(".")[0])
5+
56

67

78
def _check_log_handler():
@@ -12,7 +13,6 @@ def _check_log_handler():
1213
# create console handler and set level to debug
1314
ch = logging.StreamHandler()
1415
ch.setLevel(logging.DEBUG)
15-
logging.root.setLevel(logging.DEBUG)
1616

1717
# create formatter
1818
formatter = logging.Formatter('[%(levelname)s] %(message)s')

pypandoc/pandoc_download.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
except ImportError:
1818
from urllib import urlopen
1919

20-
from .handler import _check_log_handler
21-
22-
logger = logging.getLogger(__name__.split('.')[0])
20+
from .handler import logger, _check_log_handler
2321

2422
DEFAULT_TARGET_FOLDER = {
2523
"win32": "~\\AppData\\Local\\Pandoc",

0 commit comments

Comments
 (0)