Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
django-logging-context
Advanced tools
django-logging-context
is BSD licensed library extending default django
logging context with following additional values:
pip install django-logging-context -y
django-logging-context
to your INSTALLED_APPS
setting like this: INSTALLED_APPS = [
...
'django_logging_context',
]
MIDDLEWARE
setting like this:MIDDLEWARE = [
'django_logging_context.middlewares.LoggingContextMiddleware',
...
]
It's important to place this LoggingContextMiddleware
at the first place in
a MIDDLEWARE
to allow to calculate duration of response more precisely.
LoggingWSGIMiddleware
in your wsgi.py
like
this:from django_logging_context.wsgi import LoggingWSGIMiddleware
application = LoggingWSGIMiddleware(get_wsgi_application())
import os
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
DB_LOG_LEVEL = os.environ.get('DB_LOG_LEVEL', LOG_LEVEL)
REQUESTS_LOG_LEVEL = os.environ.get('REQUESTS_LOG_LEVEL', LOG_LEVEL)
CELERY_LOG_LEVEL = os.environ.get('CELERY_LOG_LEVEL', LOG_LEVEL)
SENTRY_LOG_LEVEL = os.environ.get('SENTRY_LOG_LEVEL', LOG_LEVEL)
LOGGING = {
'version': 1,
'loggers': {
'django': {'level': LOG_LEVEL},
'django.db': {'level': DB_LOG_LEVEL},
'urllib3': {'level': REQUESTS_LOG_LEVEL},
'celery': {'level': CELERY_LOG_LEVEL},
'sentry': {'level': SENTRY_LOG_LEVEL},
},
'root': {
'level': LOG_LEVEL,
'handlers': ['console']
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'filters': ['extending_context_filter']
}
},
'filters': {
'extending_context_filter': {
'()': 'django_logging_context.logging.ContextExtendingFilter'
}
},
'formatters': {
'verbose': {
'format': ('[django] %(levelname)s %(asctime)s'
' %(name)s/%(module)s'
' %(process)d/%(thread)d'
' request_id: %(request_id)s'
' remote_addr: %(remote_addr)s'
' user_id: %(user_id)s'
' username: %(username)s'
' duration: %(response_duration)s'
' uri: %(uri)s'
' %(message)s')
},
},
}
[django] INFO 2021-04-08 18:12:13,573 django.server/basehttp 47385/123145535799296 request_id: ea9a2dfd-a662-4632-84d0-d0c5151b5422 remote_addr: 127.0.0.1 user_id: 2 username: root duration: 1.548695s uri: http://127.0.0.1:8000/login/?next=/ "GET /admin/ HTTP/1.1" 200 46937
FAQs
Django library extending default logging context
We found that django-logging-context demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.