Skip to content

Commit

Permalink
Merge pull request #13 from Djacket/init-logging
Browse files Browse the repository at this point in the history
Configured logging.
  • Loading branch information
moeenz authored Apr 26, 2018
2 parents 1a80705 + 1e65df5 commit 8f5258a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@
# 0.2.2 (April 22, 2018)
* TravisCI configuration added.
- Configuration for continuous integration in `Travis` build system added, regarding issue #10.


# 0.2.3 (April 27, 2018)
* Minor updates.
- Configured `Django` logging for production.
- Migrated from `Popen` to the new `run` function for calling system commands.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A free and open source Git server written in [Python/Django](https://www.djangop
<img src="index.png" alt="Index"/>
</p>

# What's New
# Important Changes
#### v0.2.0
Djacket is dockerized and so much easier to use. If you are coming from version 0.1.0, please read the [migration guide](https://github.com/Djacket/djacket/wiki/Migration-from-v0.1.0) to keep yourself updated.
#### v0.2.1
Expand Down
39 changes: 34 additions & 5 deletions core/backend/djacket/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def osenv(env_name):
WSGI_APPLICATION = 'djacket.wsgi.application'


# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True if osenv('DJKR_MODE') in ['dev', 'ci'] else False


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# Currently there's not much of a database transaction (only on user/repository creation)
Expand All @@ -101,6 +106,35 @@ def osenv(env_name):
}
}


# Logging for production.
if not DEBUG:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s [%(module)s] %(process)d | %(message)s'
}
},
'handlers': {
'file': {
'level': 'DEBUG',
'formatter': 'verbose',
'class': 'logging.FileHandler',
'filename': '/srv/run/logs/django.log'
}
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True
}
}
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

Expand Down Expand Up @@ -153,11 +187,6 @@ def osenv(env_name):
SECRET_KEY = osenv('DSCT_KY')


# SECURITY WARNING: don't run with debug turned on in production!

DEBUG = True if osenv('DJKR_MODE') in ['dev', 'ci'] else False


# For security reasons, set domain or host of your site in ALLOWED_HOSTS
# e.g.
# ALLOWED_HOSTS = ['exampledomain.com']
Expand Down
5 changes: 5 additions & 0 deletions core/backend/git/http.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from django.http import HttpResponse, HttpResponseNotFound

from git.repo import Repo
Expand All @@ -7,6 +9,8 @@
GIT_HTTP_SERVICE_UPLOAD_PACK = 2
GIT_HTTP_SERVICE_RECEIVE_PACK = 3

logger = logging.getLogger('django')


def get_http_error(exception):
"""
Expand Down Expand Up @@ -159,4 +163,5 @@ def get_http_service_rpc(self):
self.set_response_payload(GIT_HTTP_SERVICE_UPLOAD_PACK)
return self
except BaseException as e:
logger.error(e)
return get_http_error(e)
19 changes: 10 additions & 9 deletions core/backend/utils/system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shlex
import shutil
from subprocess import Popen, PIPE, STDOUT
import os, shlex, shutil, logging
from subprocess import PIPE, run

logger = logging.getLogger('django')


def run_command(cmd, data, location, chw):
Expand All @@ -18,14 +18,15 @@ def run_command(cmd, data, location, chw):
elif location is not None and chw is False:
cmd = '{0} {1}'.format(cmd, location)

r = Popen(shlex.split(cmd), stdout=PIPE, stdin=PIPE, stderr=PIPE, cwd=cwd)
result = run(shlex.split(cmd), input=data, stdout=PIPE, stderr=PIPE, cwd=cwd)

if result.stderr != b'':
logger.info('RUN_COMMAND -> ERR ({})'.format(result.stderr))

if data is None:
output = r.communicate()[0].decode('utf-8')
return result.stdout.decode('utf-8')
else:
output = r.communicate(input=data)[0]

return output
return result.stdout


def remove_tree(path):
Expand Down

0 comments on commit 8f5258a

Please sign in to comment.