Skip to content

chore(typing): add setLevel and addHandler to Logger for mypy/pyright #2388

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

Merged
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
10 changes: 8 additions & 2 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ def _init_logger(self, formatter_options: Optional[Dict] = None, log_level: Unio
if self.child or is_logger_preconfigured:
return

self._logger.setLevel(self._determine_log_level(log_level))
self.setLevel(self._determine_log_level(log_level))
self._configure_sampling()
self._logger.addHandler(self.logger_handler)
self.addHandler(self.logger_handler)
self.structure_logs(formatter_options=formatter_options, **kwargs)

# Maintenance: We can drop this upon Py3.7 EOL. It's a backport for "location" key to work
Expand Down Expand Up @@ -633,6 +633,12 @@ def get_correlation_id(self) -> Optional[str]:
return self.registered_formatter.log_format.get("correlation_id")
return None

def setLevel(self, level: Union[str, int]) -> None:
return self._logger.setLevel(level)

def addHandler(self, handler: logging.Handler) -> None:
return self._logger.addHandler(handler)

@property
def registered_handler(self) -> logging.Handler:
"""Convenience property to access the first logger handler"""
Expand Down