Skip to content

Commit 00cdf3a

Browse files
committed
allow turning off logging middleware
1 parent c242038 commit 00cdf3a

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class YourSettings(BaseServiceSettings):
397397
logging_unset_handlers: list[str] = ["uvicorn", "uvicorn.access"]
398398
logging_extra_processors: list[typing.Any] = []
399399
logging_exclude_endpoints: list[str] = []
400+
logging_turn_off_middleware: bool = False
400401
```
401402

402403
Parameters description:
@@ -407,6 +408,7 @@ Parameters description:
407408
- `logging_unset_handlers` - Unset logger handlers.
408409
- `logging_extra_processors` - Set additional structlog processors if needed.
409410
- `logging_exclude_endpoints` - Exclude logging on specific endpoints.
411+
- `logging_turn_off_middleware` - Turning off logging middleware.
410412

411413
### CORS
412414

microbootstrap/bootstrappers/fastapi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ def bootstrap_after(self, application: ApplicationT) -> ApplicationT:
100100
@FastApiBootstrapper.use_instrument()
101101
class FastApiLoggingInstrument(LoggingInstrument):
102102
def bootstrap_after(self, application: ApplicationT) -> ApplicationT:
103-
application.add_middleware( # type: ignore[call-arg]
104-
build_fastapi_logging_middleware(self.instrument_config.logging_exclude_endpoints), # type: ignore[arg-type]
105-
)
103+
if not self.instrument_config.logging_turn_off_middleware:
104+
application.add_middleware( # type: ignore[call-arg]
105+
build_fastapi_logging_middleware(self.instrument_config.logging_exclude_endpoints), # type: ignore[arg-type]
106+
)
106107
return application
107108

108109

microbootstrap/bootstrappers/litestar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ def bootstrap_before(self) -> dict[str, typing.Any]:
118118
@LitestarBootstrapper.use_instrument()
119119
class LitestarLoggingInstrument(LoggingInstrument):
120120
def bootstrap_before(self) -> dict[str, typing.Any]:
121+
if self.instrument_config.logging_turn_off_middleware:
122+
return {}
123+
121124
return {"middleware": [build_litestar_logging_middleware(self.instrument_config.logging_exclude_endpoints)]}
122125

123126

microbootstrap/instruments/logging_instrument.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class LoggingConfig(BaseInstrumentConfig):
126126
default_factory=lambda: ["uvicorn", "uvicorn.access"],
127127
)
128128
logging_exclude_endpoints: list[str] = pydantic.Field(default_factory=list)
129+
logging_turn_off_middleware: bool = False
129130

130131

131132
class LoggingInstrument(Instrument[LoggingConfig]):

0 commit comments

Comments
 (0)