Skip to content

Commit

Permalink
Merge pull request #287 from vipyrsec/add-toggleable-json-logging
Browse files Browse the repository at this point in the history
Add toggleable JSON logging
  • Loading branch information
Robin5605 authored Jul 18, 2024
2 parents ccda8a1 + b21df78 commit 642f40b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/mainframe/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Mainframe(EnvConfig):

job_timeout: int = 60 * 2

enable_json_logging: bool = False


mainframe_settings = Mainframe() # pyright: ignore

Expand Down
17 changes: 5 additions & 12 deletions src/mainframe/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sentry_sdk.integrations.logging import LoggingIntegration
from structlog_sentry import SentryProcessor

from mainframe.constants import GIT_SHA, Sentry
from mainframe.constants import GIT_SHA, Sentry, mainframe_settings
from mainframe.dependencies import validate_token, validate_token_override
from mainframe.endpoints import routers
from mainframe.models.schemas import ServerMetadata
Expand Down Expand Up @@ -49,17 +49,10 @@ def configure_logger():
cache_logger_on_first_use=True,
)

# log_renderer: structlog.types.Processor
# # If running in production, render logs with JSON.
# if mainframe_settings.production:
# log_renderer = structlog.processors.JSONRenderer()
# else:
# # If running in a development environment, pretty print logs
# log_renderer = structlog.dev.ConsoleRenderer()

# TODO: Once infra for log aggregation is up and running, remove this and go back to
# TODO: JSON logging in production.
log_renderer = structlog.dev.ConsoleRenderer(colors=False)
if mainframe_settings.enable_json_logging is True:
log_renderer = structlog.processors.JSONRenderer()
else:
log_renderer = structlog.dev.ConsoleRenderer(colors=False)

formatter = structlog.stdlib.ProcessorFormatter(
foreign_pre_chain=shared_processors,
Expand Down

0 comments on commit 642f40b

Please sign in to comment.