Skip to content

Commit

Permalink
Merge pull request #2670 from prefeiturasp/release/8.18.0
Browse files Browse the repository at this point in the history
Release/8.18.0
  • Loading branch information
rayanemsantos authored Feb 1, 2024
2 parents a5fbc1d + 7ef23c1 commit d344737
Show file tree
Hide file tree
Showing 54 changed files with 1,221 additions and 231 deletions.
12 changes: 11 additions & 1 deletion config/api_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from waffle.decorators import waffle_flag

from django.conf import settings
from django.urls import path, include
from django.urls import path
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.routers import DefaultRouter, SimpleRouter
Expand Down Expand Up @@ -90,6 +90,12 @@

from sme_ptrf_apps.mandatos.api.views import MandatosViewSet, ComposicoesViewSet, OcupantesCargosViewSet, CargosComposicoesViewSet

from sme_ptrf_apps.logging.simulador_de_logs.simulador_de_logs_view import (
SimuladorDeLogsView,
SimuladorDeLogsAsyncView,
SimuladorDeLogsSecudarioView,
SimuladorDeLogsSecundarioAsyncView,
)

@api_view()
def versao(request):
Expand Down Expand Up @@ -192,4 +198,8 @@ def teste_flag_view(request):
path("teste-flag", teste_flag_view),
path("login", LoginView.as_view()),
path("feature-flags", feature_flags),
path("simular-logs", SimuladorDeLogsView.as_view()),
path("simular-logs-sec", SimuladorDeLogsSecudarioView.as_view()),
path("simular-logs-async", SimuladorDeLogsAsyncView.as_view()),
path("simular-logs-sec-async", SimuladorDeLogsSecundarioAsyncView.as_view()),
]
87 changes: 50 additions & 37 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,54 +214,67 @@

# LOGGING CONFIGURATION
# ------------------------------------------------------------------------------

# Verifica se o logging para o RabbitMQ está habilitado
enable_rabbitmq_logging = env.bool("ENABLE_RABBITMQ_LOGGING", default=False)

# Handlers
LOGGING_HANDLERS = {
"console": {
"level": env("DJANGO_LOG_LEVEL", default="INFO"),
"class": "logging.StreamHandler",
"formatter": "verbose",
}
}

if enable_rabbitmq_logging:
LOGGING_HANDLERS["rabbitmq"] = {
"level": env("RABBITMQ_LOG_LEVEL", default="INFO"),
"class": "sme_ptrf_apps.logging.handlers.RabbitMQHandler",
"host": env("RABBITMQ_HOST"),
"virtual_host": env("RABBITMQ_VIRTUAL_HOST"),
"queue": env("RABBITMQ_LOG_QUEUE"),
"username": env("RABBITMQ_USERNAME"),
"password": env("RABBITMQ_PASSWORD"),
}

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"verbose": {
"()": "sme_ptrf_apps.logging.formaters.CustomFormatter",
"format": "%(levelname)s %(asctime)s %(module)s "
"%(process)d %(thread)d %(message)s"
}
"%(process)d %(thread)d %(message)s "
"%(operacao)s %(operacao_id)s %(username)s %(observacao)s "
},
},
"handlers": {
"console": {
"level": env("DJANGO_LOG_LEVEL", default="INFO"),
"class": "logging.StreamHandler",
"formatter": "verbose",
"handlers": LOGGING_HANDLERS,
'loggers': {
'django': {
'handlers': ['console'],
'level': 'WARNING',
'propagate': True,
},
'celery': {
'level': 'INFO',
'handlers': ['console'],
'propagate': True,
},
# 'elasticapm': {
# 'level': env('ELASTIC_APM_LOG_LEVEL', default='INFO'),
# 'class': 'elasticapm.contrib.django.handlers.LoggingHandler',
# },
# api_sme_ptrf_apps identifica os logs definidos por um ContextualLogger
'api_sme_ptrf_apps': {
'handlers': ['console'] + (['rabbitmq'] if enable_rabbitmq_logging else []),
'level': 'INFO',
'propagate': False,
},
},
"root": {
"level": env("DJANGO_LOG_LEVEL", default="INFO"),
"handlers": ["console"],
},
# "root": {"level": env("DJANGO_LOG_LEVEL", default="INFO"), "handlers": ["console", "elasticapm"]},
"root": {"level": env("DJANGO_LOG_LEVEL", default="INFO"), "handlers": ["console"]},
# "loggers": {
# "django.db.backends": {
# "level": "ERROR",
# "handlers": ["console"],
# "propagate": False,
# },
# # Errors logged by the SDK itself
# "sentry_sdk": {"level": "ERROR", "handlers": ["console"], "propagate": False},
# "django.security.DisallowedHost": {
# "level": "ERROR",
# "handlers": ["console"],
# "propagate": False,
# },
# 'django': {
# 'handlers': ['elasticapm'],
# 'level': 'WARNING',
# 'propagate': False,
# },
# 'elasticapm.errors': {
# 'level': 'ERROR',
# 'handlers': ['console'],
# 'propagate': False,
# },
# },
}


# CELERY SETTINGS
# ------------------------------------------------------------------------------
if USE_TZ:
Expand Down
13 changes: 13 additions & 0 deletions env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ ELASTIC_APM_SECRET_TOKEN=
ELASTIC_APM_DEBUG=True
ELASTIC_APM_SERVER_URL=
ELASTIC_APM_ENVIRONMENT=

#Configurações de nível de log
DJANGO_LOG_LEVEL=INFO
LOG_ENVIRONMENT=Desenvolvimento

# Integração com RabbitMQ para logs
ENABLE_RABBITMQ_LOGGING=False
RABBITMQ_HOST=
RABBITMQ_VIRTUAL_HOST=
RABBITMQ_USERNAME=
RABBITMQ_PASSWORD=
RABBITMQ_LOG_QUEUE=
RABBITMQ_LOG_LEVEL=
4 changes: 4 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ django-redis==4.11.0
elastic-apm==6.15.1
psutil==5.9.4

# Integração com RabbitMQ
# ------------------------------------------------------------------------------
pika==1.3.2

# Outras libs e utilitários
# ------------------------------------------------------------------------------
Babel==2.12.1
Expand Down
2 changes: 1 addition & 1 deletion sme_ptrf_apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "8.17.1"
__version__ = "8.18.0"

__version_info__ = tuple(
[
Expand Down
Loading

0 comments on commit d344737

Please sign in to comment.