Open
Description
The utility methods on Context for logging all document **extra
as being passed forward to the logger. However, Context.log
does not actually allow any additional kwargs to be passed. This results in errors such as
Context.log() got an unexpected keyword argument
To Reproduce
Any usage of the context methods with extra kwargs will produce the error, for example
await context.info(
"request finished",
channel_id=channel_id,
status=response.get("ok"),
)
Expected behavior
The Context.log
method is documented with
Args:
level: Log level (debug, info, warning, error)
message: Log message
logger_name: Optional logger name
**extra: Additional structured data to include
This (and the helper methods) should either be documented as not supporting additional structured data or the log message data
needs to be structured, for example, something like this
async def log(
self,
level: Literal["debug", "info", "warning", "error"],
message: str,
*,
logger_name: str | None = None,
**extra: Any
) -> None:
"""Send a log message to the client.
Args:
level: Log level (debug, info, warning, error)
message: Log message
logger_name: Optional logger name
**extra: Additional structured data to include
"""
log_data = {
"message": message, **extra
}
await self.request_context.session.send_log_message(
level=level, data=log_data, logger=logger_name
)
Metadata
Metadata
Assignees
Labels
No labels