Skip to content

Commit

Permalink
Add no new logging handlers when reloading the module.
Browse files Browse the repository at this point in the history
User @epogrebnyak found the bug. Fixes #11. Closes #27.
  • Loading branch information
danijar committed Aug 11, 2019
1 parent 8ce8311 commit 393e0b4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
7 changes: 4 additions & 3 deletions handout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
logger = logging.getLogger('handout')
logger.setLevel(logging.INFO)
logger.propagate = False # Global logger should not print messages again.
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter('%(message)s'))
logger.addHandler(handler)
if not logger.handlers: # Reloading the module should not add another handler.
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter('%(message)s'))
logger.addHandler(handler)
3 changes: 3 additions & 0 deletions handout/handout.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, directory, title='Handout'):
self._title = title
self._blocks = collections.defaultdict(list)
self._pending = []
# The logger is configured in handout/__init__.py to make it available
# right after importing the handout package. This allows the user to change
# the logging level, message format, etc.
self._logger = logging.getLogger('handout')
for info in inspect.stack():
if info.filename == __file__:
Expand Down
Empty file removed handout/tests/__init__.py
Empty file.
6 changes: 4 additions & 2 deletions handout/tests/test_handout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import handout


def test_handout_on_title_arg_inserts_title(tmp_path):
output = handout.Handout(directory=tmp_path, title='This string')._generate(source='')
assert '<title>This string</title>' in output
doc = handout.Handout(directory=tmp_path, title='This string')
output = doc._generate(source='')
assert '<title>This string</title>' in output

0 comments on commit 393e0b4

Please sign in to comment.