When using AsyncBoundLogger with add_logger_name, I get: AttributeError: 'BoundLoggerFilteringAtNotset' object has no attribute 'name'
My Code:
import logging
import structlog
from structlog import get_logger
import asyncio
loop = asyncio.get_event_loop()
def define_structlog(log_level=logging.INFO, pretty: bool = False, set_bugsnag: bool = False) -> None:
processors = [
structlog.stdlib.add_logger_name,
]
structlog.configure(
processors=processors,
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
cache_logger_on_first_use=True,
)
def wrap_async(logger) -> structlog.stdlib.AsyncBoundLogger:
return structlog.wrap_logger(logger, wrapper_class=structlog.stdlib.AsyncBoundLogger)
async def main():
define_structlog()
logger = wrap_async(get_logger())
await logger.info("hay")
if __name__ == "__main__":
loop.run_until_complete(main())
Is there is something wrong with my code?
Fixed it, needed to add wrapper_class=structlog.stdlib.BoundLogger in the structlog.configure function