Skip to content

Commit 7a94628

Browse files
committed
Add different structlog processors, based on the renderer
1 parent 9b0ac3c commit 7a94628

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

config/settings/loggers/setup.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ def setup_settings(INSTALLED_APPS, MIDDLEWARE, middleware_position=None):
3434

3535
@staticmethod
3636
def setup_structlog():
37+
from django.conf import settings
38+
39+
from config.settings.loggers.settings import LoggingFormat
40+
41+
logging_format = settings.LOGGING_FORMAT
42+
43+
extra_processors = []
44+
45+
if logging_format == LoggingFormat.DEV:
46+
extra_processors = [
47+
structlog.processors.format_exc_info,
48+
]
49+
50+
if logging_format in [LoggingFormat.JSON, LoggingFormat.LOGFMT]:
51+
dict_tracebacks = structlog.processors.ExceptionRenderer(
52+
structlog.processors.ExceptionDictTransformer(show_locals=False)
53+
)
54+
extra_processors = [
55+
dict_tracebacks,
56+
]
57+
3758
structlog.configure(
3859
processors=[
3960
structlog.contextvars.merge_contextvars,
@@ -44,8 +65,7 @@ def setup_structlog():
4465
structlog.stdlib.PositionalArgumentsFormatter(),
4566
structlog.processors.StackInfoRenderer(),
4667
structlog.dev.set_exc_info,
47-
structlog.processors.format_exc_info,
48-
# structlog.processors.dict_tracebacks,
68+
*extra_processors,
4969
structlog.processors.UnicodeDecoder(),
5070
structlog.processors.CallsiteParameterAdder(
5171
{

0 commit comments

Comments
 (0)