Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass service identity as logger name #101

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion karton/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
self.config = config or Config()
self.backend = backend or KartonBackend(self.config)

self.log_handler = KartonLogHandler(backend=self.backend)
self.log_handler = KartonLogHandler(backend=self.backend, name=self.identity)
self.current_task: Optional[Task] = None

def setup_logger(self, level: Optional[Union[str, int]] = None) -> None:
Expand Down
5 changes: 3 additions & 2 deletions karton/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
class KartonLogHandler(logging.Handler):
"""Base class for karton loggers"""

def __init__(self, backend: KartonBackend) -> None:
def __init__(self, backend: KartonBackend, name: str) -> None:
logging.Handler.__init__(self)
self.backend = backend
self.task: Optional[Task] = None
self.is_consumer_active: bool = True
self.logger_name: str = name

def set_task(self, task: Task) -> None:
self.task = task
Expand Down Expand Up @@ -51,7 +52,7 @@ def emit(self, record: logging.LogRecord) -> None:
log_line["task"] = self.task.serialize()

log_consumed = self.backend.produce_log(
log_line, logger_name=record.name, level=record.levelname
log_line, logger_name=self.logger_name, level=record.levelname
)
if self.is_consumer_active and not log_consumed:
warnings.warn("There is no active log consumer to receive logged messages.")
Expand Down