Skip to content

Commit

Permalink
Merge pull request #111 from crhan/ruohan.chen/exception_logging
Browse files Browse the repository at this point in the history
improve exception logging
  • Loading branch information
wjo1212 committed Jan 7, 2019
2 parents aee03f0 + 6e08123 commit 7b1cefe
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions aliyun/log/consumer/shard_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .config import ConsumerStatus
from .fetched_log_group import FetchedLogGroup
from .tasks import ProcessTaskResult, InitTaskResult, FetchTaskResult
from .tasks import ProcessTaskResult, InitTaskResult, FetchTaskResult, TaskResult
from .tasks import consumer_fetch_task, consumer_initialize_task, \
consumer_process_task, consumer_shutdown_task
from .exceptions import ClientWorkerException
Expand Down Expand Up @@ -189,12 +189,20 @@ def cancel_current_fetch(self):

def _sample_log_error(self, result):
# record the time when error happens
if not isinstance(result, TaskResult):
return

exc = result.get_exception()
if exc is None:
return

current_time = time.time()
if result is not None \
and result.get_exception() is not None \
and current_time - self.last_log_error_time > 5:
self.logger.warning(result.get_exception(), exc_info=True)
self.last_log_error_time = current_time
if current_time - self.last_log_error_time <= 5:
return

self.logger.warning(exc, exc_info=exc)
self.last_log_error_time = current_time


def _update_status(self, task_succcess):
if self.consumer_status == ConsumerStatus.SHUTTING_DOWN:
Expand Down

0 comments on commit 7b1cefe

Please sign in to comment.