Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
dependencies.py: fixup bug with shared logger extra
Browse files Browse the repository at this point in the history
- Do not overwrite existing shared logger. It produces a bug with
  one logging extra (extra with worker_ctx) for each worker (but it
  should be unique per worker). Return only logging adapter, and use
  _worker_ctx_to_dict to get worker's context in worker_result() function.
  • Loading branch information
vldpro committed Nov 23, 2018
1 parent 3796c7c commit 0387113
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions nameko_worker_logger/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def __init__(self, logger_name):
def get_dependency(self, worker_ctx):
"""Create logger adapter with worker's contextual data."""
worker_info = {'worker': _worker_ctx_to_dict(worker_ctx)}
self.logger = logging.LoggerAdapter(self.logger, extra=worker_info)
return self.logger
adapter = logging.LoggerAdapter(self.logger, extra=worker_info)
return adapter

def worker_result(self, worker_ctx, result=None, exc_info=None):
"""Log exception info, if it is present."""
if exc_info is None:
return
exception_info = _exception_info_to_dict(exc_info)
self.logger.error({'exception_info': exception_info})
exception_info = {'exception_info': _exception_info_to_dict(exc_info)}
worker_info = {'worker': _worker_ctx_to_dict(worker_ctx)}
self.logger.error(exception_info, extra=worker_info)

0 comments on commit 0387113

Please sign in to comment.