Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Update django-json-logging for console out
Browse files Browse the repository at this point in the history
Had to make this change to our forked django-json-logging library. Still
hammering away on that and will have to open a PR accordingly.
  • Loading branch information
msheiny committed May 3, 2019
1 parent 8360caa commit 2f54446
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ update-pip-dependencies: ## Uses pip-compile to update requirements.txt
# It is critical that we run pip-compile via the same Python version
# that we're generating requirements for, otherwise the versions may
# be resolved differently.
<<<<<<< HEAD
docker run -v "$(DIR)/securethenews:/code" -it python:3.6-slim \
bash -c 'pip install pip-tools && apt-get update && apt-get install git -y && pip-compile \
--output-file /code/requirements.txt /code/requirements.in'
=======
docker run -v "$(DIR)/securethenews:/code" -it python:3.4-slim \
bash -c 'apt-get update && apt-get install git -y \
&& pip install pip-tools && pip-compile \
--output-file /code/requirements.txt /code/requirements.in'
>>>>>>> Use upstream python container

.PHONY: safety
safety: ## Runs `safety check` to check python dependencies for vulnerabilities
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: '3'
version: "3"
networks:
app:
services:
Expand Down Expand Up @@ -44,12 +44,12 @@ services:
- node
- postgresql
environment:
DJANGO_LOG_CONSOLE: "yes"
DJANGO_DB_PASSWORD: securethenewspassword
DJANGO_DB_USER: securethenews
DJANGO_DB_NAME: securethenewsdb
DJANGO_DB_PORT: 5432
DJANGO_DB_HOST: db
DJANGO_LOG_PATH: /django-logs
DJANGO_XMLTEST_OUTPUT: "yes"
DEPLOY_ENV: dev
working_dir: /django
Expand Down
34 changes: 17 additions & 17 deletions docker/ProdDjangoDockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ RUN cd /src-files && ( npm install && gulp build:production )
FROM python@sha256:bfac58481666aeb60ff6354e81afe888cc8c7b1effb1039870377fc7fa86ef43

RUN apk add --no-cache \
bash \
curl \
gcc \
git \
# pillow dep
jpeg-dev \
libffi-dev \
musl-dev \
paxctl \
postgresql-dev \
# pillow dep
tiff-dev \
# pillow dep
zlib-dev
bash \
curl \
gcc \
git \
# pillow dep
jpeg-dev \
libffi-dev \
musl-dev \
paxctl \
postgresql-dev \
# pillow dep
tiff-dev \
# pillow dep
zlib-dev

COPY docker/django-start.sh /usr/local/bin
RUN chmod +x /usr/local/bin/django-start.sh
Expand All @@ -50,9 +50,9 @@ RUN pip install -r /django/securethenews/requirements.txt
# Really not used in production. Needed for mapped named volume
# permission handling https://github.com/docker/compose/issues/3270
RUN mkdir /django-media /django-static /django-logs && \
chown -R gcorn: /django-media && \
chown -R gcorn: /django-static && \
chown -R gcorn: /django-logs
chown -R gcorn: /django-media && \
chown -R gcorn: /django-static && \
chown -R gcorn: /django-logs

RUN mkdir -p /etc/gunicorn && chown -R gcorn: /etc/gunicorn
COPY docker/gunicorn/gunicorn.py /etc/gunicorn/gunicorn.py
Expand Down
3 changes: 2 additions & 1 deletion docker/djangodocker.snippet
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python@3.7-alpine
# 3.6.5-alpine3.7 - May 11, 2018
FROM python@sha256:bfac58481666aeb60ff6354e81afe888cc8c7b1effb1039870377fc7fa86ef43

RUN apk add --no-cache \
bash \
Expand Down
4 changes: 2 additions & 2 deletions securethenews/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
# pip-compile --output-file /code/requirements.txt /code/requirements.in
#
-e git+https://github.com/freedomofpress/django-logging.git@51f4fd4b02fafc3d6d9cddb5658247497404df7e#egg=django-logging-json
-e git+https://github.com/freedomofpress/django-logging.git@ff46c7397b324744f948e342dda563ecab1ceed3#egg=django-logging-json
asn1crypto==0.22.0 # via cryptography
beautifulsoup4==4.6.0 # via pytablereader, wagtail
boto3==1.7.48 # via django-storages
boto3==1.7.48
botocore==1.10.48 # via boto3, s3transfer
cachetools==2.1.0 # via google-auth
certifi==2017.7.27.1 # via requests
Expand Down
38 changes: 28 additions & 10 deletions securethenews/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,28 @@
#

LOG_DIR = os.environ.get('DJANGO_LOG_PATH', os.path.join(BASE_DIR, 'logs'))
LOG_TO_CONSOLE = bool(os.environ.get('DJANGO_LOG_CONSOLE', False))

DJANGO_LOGGING = {
"CONSOLE_LOG": False,
"CONSOLE_LOG": LOG_TO_CONSOLE,
"SQL_LOG": False,
"DISABLE_EXISTING_LOGGERS": False,
"PROPOGATE": False,
"LOG_LEVEL": os.environ.get('DJANGO_LOG_LEVEL', 'info'),
"LOG_PATH": LOG_DIR
"LOG_PATH": LOG_DIR,
"INDENT_CONSOLE_LOG": 0
}

# Ensure base log directory exists
if not os.path.exists(LOG_DIR):
if not os.path.exists(LOG_DIR) and not LOG_TO_CONSOLE:
os.makedirs(LOG_DIR)
DJANGO_OTHER_LOG = os.path.join(LOG_DIR, 'django-other.log')

# Logs other than tracebacks and requests
GENERIC_LOG_HANDLER = 'rotate'
if LOG_TO_CONSOLE:
GENERIC_LOG_HANDLER = 'console'

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand All @@ -212,39 +219,50 @@
'backupCount': 5,
'maxBytes': 10000000,
'filename': os.environ.get('DJANGO_LOGFILE', DJANGO_OTHER_LOG),
'formatter': 'django_builtin'
'formatter': 'json_out'
},

'console': {
'class': 'logging.StreamHandler',
'formatter': 'json_out'
},

'null': {
'class': 'logging.NullHandler',
}
},
'formatters': {
'django_builtin': {
'json_out': {
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
'format': "%(asctime)s %(levelname)s %(name)s "
'format': "%(levelname)s %(created)s %(name)s "
"%(module)s %(message)s"
}
},
'loggers': {
'django.template': {
'handlers': ['rotate'],
'handlers': [GENERIC_LOG_HANDLER],
'propagate': False,
},
'django.db.backends': {
'handlers': ['rotate'],
'handlers': [GENERIC_LOG_HANDLER],
'propagate': False,
},
'django.security': {
'handlers': ['rotate'],
'handlers': [GENERIC_LOG_HANDLER],
'propagate': False,
},
# These are already handled by the django json logging library
'django.request': {
'handlers': ['null'],
'propagate': False,
},
# Log entries from runserver
'django.server': {
'handlers': ['null'],
'propagate': False,
},
'': {
'handlers': ['rotate'],
'handlers': [GENERIC_LOG_HANDLER],
'propagate': False,
},
},
Expand Down

0 comments on commit 2f54446

Please sign in to comment.