`logging` module cause error due to `format`

First and foremost, thanks for this package.

I am trying to use this package for some GET queries but it creates error if I have set the `format` for the logging module. Have these example snippets:

This will work just fine
```python
import requests
import logging
logging.basicConfig(filename = 'log.txt',
                    encoding = 'utf-8',
                    level = logging.DEBUG)
resp = requests.get("https://ifconfig.io/")
```

This will throw error
```python
import requests
import logging
logging.basicConfig(filename = 'log.txt',
                    encoding = 'utf-8',
                    format = '%(asctime)s;%(function)s;%(message)s',
                    level = logging.DEBUG)
resp = requests.get("https://ifconfig.io/")
```

<details>
<summary>To see the output error, expand this</summary>

```
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 440, in format
    return self._format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 436, in _format
    return self._fmt % values
KeyError: 'function'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 681, in format
    s = self.formatMessage(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 650, in formatMessage
    return self._style.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 442, in format
    raise ValueError('Formatting field not found in record: %s' % e)
ValueError: Formatting field not found in record: 'function'
Call stack:
  File "<stdin>", line 1, in <module>
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 692, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 281, in _get_conn
    return conn or self._new_conn()
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1003, in _new_conn
    log.debug(
Message: 'Starting new HTTPS connection (%d): %s:%s'
Arguments: (1, 'ifconfig.io', 443)
--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 440, in format
    return self._format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 436, in _format
    return self._fmt % values
KeyError: 'function'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 1100, in emit
    msg = self.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 943, in format
    return fmt.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 681, in format
    s = self.formatMessage(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 650, in formatMessage
    return self._style.format(record)
  File "/usr/lib/python3.10/logging/__init__.py", line 442, in format
    raise ValueError('Formatting field not found in record: %s' % e)
ValueError: Formatting field not found in record: 'function'
Call stack:
  File "<stdin>", line 1, in <module>
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/home/mehrad/Documents/git_repos/projectX/Python/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 456, in _make_request
    log.debug(
Message: '%s://%s:%s "%s %s %s" %s %s'
Arguments: ('https', 'ifconfig.io', 443, 'GET', '/', 'HTTP/1.1', 200, None)
```

</details>

And of course the error can be bypassed by changing the logging level to for example `logging.INFO`, but that is besides the point.

I'm now that savvy in python world to know if this should be treated as a bug of this package or there is a correct way to handle this in my own code. To me it seems that this is a bug as `requests` should be able to change the format internally on the fly and set it back to user defined. But again, I'm not that pro, so any guidance and suggestions is very welcome.

I don't see anything that should be populating the function variable for you. Python doesn't have a way to log the function name but can log the module name via `name`. This appears to be an issue in the format string you chose, not this library (which itself contains no log statements) or its dependencies 

@sigmavirus24 Thanks for your answer but:

## 1 

> this library (which itself contains no log statements) or its dependencies

a simple `rg` says otherwise:

https://github.com/psf/requests/blob/15585909c3dd3014e4083961c8a404709450151c/requests/__init__.py#L145

https://github.com/psf/requests/blob/15585909c3dd3014e4083961c8a404709450151c/requests/__init__.py#L177

-------

## 2

> This appears to be an issue in the format string you chose

I should be able to use whatever format string that I see fit for my project, and dependencies (i.e `requests` should not either dictate a format to the project nor they should fail. What am I missing? Also, my project works just fine if I don't try to use anything from `requests` package. the moment I start using this package I get the error that I mentioned above.

-------

## 3

> Python doesn't have a way to log the function name but can log the module name via name.

I think you are misunderstanding what I mean. the `%(function)` in the format is something that I'm passing as string to the logging. It has nothing to do with this. but if you are curious, I do this in python to get the function that have called my logging function:

```python
tmp_caller = sys._getframe().f_back.f_code.co_name
tmp_caller={'function': tmp_caller}
logging.critical("some stuff here", extra = tmp_caller)
```

and you can see that it works if you replace the string in the "tmp_caller" as the following:

```python
import logging
logging.basicConfig(filename = 'log.txt',
                    encoding = 'utf-8',
                    format = '%(asctime)s;%(function)s;%(message)s',
                    level = logging.DEBUG)

tmp_caller = "func_blah_blah"
tmp_caller = {'function': tmp_caller}
logging.critical("some stuff here", extra = tmp_caller)
```


> simple rg says otherwise

You didn't understand me. There's an import and a handler registered but we don't log anything. If you look at your stack trace the module the exception is coming from is not requests but our dependency urllib3. 

> I  should be able to use whatever format string that I see fit for my project, and dependencies (i.e requests should not either dictate a format to the project nor they should fail. What am I missing?

What you're missing is that you're configuring that string for everything running in the process, that's what `basicConfig` does. For that to work, every dependency needs to provide `function` to be formatted into the log record. Most will certainly not do that. You could create your own LogRecord class so it's created with a function value always. 

Otherwise, if you want to overwrite all other configuration of how log messages must be formatted, you need to ensure the values you want templated exist everywhere. 

> I think you are misunderstanding what I mean. the %(function) in the format is something that I'm passing as string to the logging. It has nothing to do with this. 

No, I'm not. Please read the stdlib documentation. I've already given you pointers to make this work, but the problem is 100% on your end. You're not understanding what you're doing and you haven't validated your expectations. Other libraries may work fine because they're not logging anything. That doesn't imply a big in this library or it's dependencies