Update `log_function` to use the right factory to create log records, to make sure that they have `request` attributes. Fixes: #8267.