Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. # logging decorator {{tag>python logging decorator}} <code> import logging from functools import wraps def log_wrap(func): logger = logging.getLogger("scrapy") @wraps(func) def wrapper_function(*args, **kwargs): if "request" in kwargs: url = kwargs["request"].url else: url = args[1].url logger.info(f"{func.__name__} url:{url}") result = func(*args, **kwargs) return result return wrapper_function </code> open/logging-decorator.txt Last modified: 2024/10/05 06:15by 127.0.0.1