Unknown model· unknown
from NVIDIA HelpSteer3 Preference
Create a python coroutine that will provide logging as a decorator to a method. Make…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Create a python coroutine that will provide logging as a decorator to a method. Make sure to provide an example.
- Assistant
Here's a Python coroutine decorator for logging that uses the built-in
loggingmodule. This decorator will log the function name, arguments, return value, and any exceptions that occur.pythonimport logging import asyncio from functools import wraps logging.basicConfig(level=logging.INFO) def log_coroutine(func): @wraps(func) async def wrapper(*args, **kwargs): logger = logging.getLogger(func.__module__ + "." + func.__qualname__) logger.info(f"Calling {func.__name__}({args}, {kwargs})") try: result = await func(*args, **kwargs) logger.info(f"{func.__name__} returned {result}") return result except Exception as e: logger.exception(f"Exception in {func.__name__}: {e}") raise return wrapper
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.