Skip to content

Commit

Permalink
Tweak logging of exceptions to exclude traceback if we have a default…
Browse files Browse the repository at this point in the history
… factory
  • Loading branch information
PLPeeters committed Dec 16, 2019
1 parent 8a5ea6d commit fd40765
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion reppy/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cachetools import LRUCache

from .policy import DefaultObjectPolicy, ReraiseExceptionPolicy
from ..exceptions import ReadTimeout
from ..robots import Robots, AllowNone, Agent
from .. import logger

Expand Down Expand Up @@ -65,7 +66,13 @@ def factory(self, url):
try:
return self.fetch(url)
except BaseException as exc:
logger.exception('Reppy cache fetch error on %s' % url)
# Log the whole stack trace only if the exception is anything other than a ReadTimeout
# or if we do not have a default factory
if isinstance(exc, ReadTimeout) and isinstance(self.cache_policy, DefaultObjectPolicy):
logger.info('Reppy cache fetch timeout on %s; using factory.' % url)
else:
logger.exception('Reppy cache fetch error on %s' % url)

return self.cache_policy.exception(url, exc)

def fetch(self, url):
Expand Down

0 comments on commit fd40765

Please sign in to comment.