Repository: litestar-org/litestar

Issue:
Bug: passing wrapper_class to StructLoggingConfig causes Pydantic exception
### Description

When trying to hook up structlog to starlite v1.51.12, I got the Pydantic exception below on starting up the app. I tried the same with the litestar v2 beta hello-world app, and it worked. I realize this may not get fixed in v1.51.x. Is there a suggested workaround?

### URL to code causing the issue

https://github.com/kpetersen-rgare/litestar-hello-world/blob/structlog-logging-config-bug/main.py

### MCVE

```python
# see URL to code
```


### Steps to reproduce

```bash
1. clone MRE repo and `poetry install`
2. `poetry run uvicorn main:app`
3. See error
```


### Screenshots

```bash
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
```


### Logs

```bash
Traceback (most recent call last):
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/bin/uvicorn", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 410, in main
    run(
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 578, in run
    server.run()
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/config.py", line 473, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/me/Developer/kpetersen-rgare/litestar-hello-world/main.py", line 19, in <module>
    logging_config = StructLoggingConfig(
                     ^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for StructLoggingConfig
wrapper_class
  Protocols with non-method members don't support issubclass() (type=type_error)
```


### Litestar Version

1.51.12

### Platform

- [ ] Linux
- [X] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)

<!-- POLAR PLEDGE BADGE START -->
## Funding
* If you would like to see an issue prioritized, make a pledge towards it!
* We receive the pledge once the issue is completed & verified

<a href="https://polar.sh/litestar-org/litestar/issues/1948">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/1948/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/1948/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->

Bug: passing wrapper_class to StructLoggingConfig causes Pydantic exception
### Description

When trying to hook up structlog to starlite v1.51.12, I got the Pydantic exception below on starting up the app. I tried the same with the litestar v2 beta hello-world app, and it worked. I realize this may not get fixed in v1.51.x. Is there a suggested workaround?

### URL to code causing the issue

https://github.com/kpetersen-rgare/litestar-hello-world/blob/structlog-logging-config-bug/main.py

### MCVE

```python
# see URL to code
```


### Steps to reproduce

```bash
1. clone MRE repo and `poetry install`
2. `poetry run uvicorn main:app`
3. See error
```


### Screenshots

```bash
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
```


### Logs

```bash
Traceback (most recent call last):
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/bin/uvicorn", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 410, in main
    run(
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/main.py", line 578, in run
    server.run()
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/config.py", line 473, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/me/Library/Caches/pypoetry/virtualenvs/starlite-hello-world-cQlwT1sN-py3.11/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/me/Developer/kpetersen-rgare/litestar-hello-world/main.py", line 19, in <module>
    logging_config = StructLoggingConfig(
                     ^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for StructLoggingConfig
wrapper_class
  Protocols with non-method members don't support issubclass() (type=type_error)
```


### Litestar Version

1.51.12

### Platform

- [ ] Linux
- [X] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)

<!-- POLAR PLEDGE BADGE START -->
## Funding
* If you would like to see an issue prioritized, make a pledge towards it!
* We receive the pledge once the issue is completed & verified

<a href="https://polar.sh/litestar-org/litestar/issues/1948">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/1948/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/1948/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->



Discussion:
Hi @kpetersen-rgare! Thanks for the report. We have squashed a few bugs around structlog issues and we should backport these.

_edited: I am a bad reader and shouldnt answer issues so late 🙃_
Hey, thanks for the quick response. I realized a simple workaround is to create my own structlog config class from the `BaseLoggingConfig` class that does not inherit from pydantic's `BaseModel`:

```python
class MyStructLoggingConfig(BaseLoggingConfig):
    def configure(self) -> "GetLogger":
        structlog.configure(
            processors=processors,
            wrapper_class=structlog.make_filtering_bound_logger(logging.DEBUG),
            logger_factory=logger_factory,
        )
        return structlog.get_logger
```
 @JacobCoffee can you take this one?
Hi yes, I will look into this starting tonight
Hi @kpetersen-rgare! Thanks for the report. We have squashed a few bugs around structlog issues and we should backport these.

_edited: I am a bad reader and shouldnt answer issues so late 🙃_
Hey, thanks for the quick response. I realized a simple workaround is to create my own structlog config class from the `BaseLoggingConfig` class that does not inherit from pydantic's `BaseModel`:

```python
class MyStructLoggingConfig(BaseLoggingConfig):
    def configure(self) -> "GetLogger":
        structlog.configure(
            processors=processors,
            wrapper_class=structlog.make_filtering_bound_logger(logging.DEBUG),
            logger_factory=logger_factory,
        )
        return structlog.get_logger
```
 @JacobCoffee can you take this one?
Hi yes, I will look into this starting tonight

Resolving patch:
diff --git a/starlite/config/logging.py b/starlite/config/logging.py
--- a/starlite/config/logging.py
+++ b/starlite/config/logging.py
@@ -259,7 +259,7 @@ class StructLoggingConfig(BaseLoggingConfig, BaseModel):
 
     processors: Optional[List[Processor]] = Field(default_factory=default_structlog_processors)  # pyright: ignore
     """Iterable of structlog logging processors."""
-    wrapper_class: Optional[Type[BindableLogger]] = Field(default_factory=default_wrapper_class)  # pyright: ignore
+    wrapper_class: Any = Field(default_factory=default_wrapper_class)  # pyright: ignore
     """Structlog bindable logger."""
     context_class: Optional[Dict[str, Any]] = None
     """Context class (a 'contextvar' context) for the logger."""


Test patch: