Last active
December 10, 2015 07:08
-
-
Save sassman/4398473 to your computer and use it in GitHub Desktop.
some useful django snippets for a smooth project start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is an extract of only loggin related stuff | |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) | |
PATH_DATA = os.path.join(ROOT_PATH, 'data') | |
PATH_LOG = os.path.join(PATH_DATA, 'logs') | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'formatters': { | |
'verbose': { | |
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' | |
}, | |
'simple': { | |
'format': '%(levelname)s %(message)s' | |
}, | |
}, | |
'handlers': { | |
'null': { | |
'level':'DEBUG', | |
'class':'django.utils.log.NullHandler', | |
}, | |
'console':{ | |
'level': 'DEBUG', | |
'class': 'logging.StreamHandler', | |
'formatter': 'simple' | |
}, | |
# I always add this handler to facilitate separating loggings | |
'file':{ | |
'level': 'DEBUG', | |
'class': 'logging.handlers.RotatingFileHandler', | |
'filename': os.path.join(PATH_LOG, 'app.log'), | |
'maxBytes': '16777216', # 16megabytes | |
'formatter': 'verbose' | |
}, | |
'mail_admins': { | |
'level': 'ERROR', | |
'class': 'django.utils.log.AdminEmailHandler', | |
'include_html': True, | |
} | |
}, | |
'loggers': { | |
'django': { | |
'handlers':['null'], | |
'propagate': True, | |
'level':'INFO', | |
}, | |
'django.request': { | |
'handlers': ['mail_admins'], | |
'level': 'ERROR', | |
'propagate': False, | |
}, | |
'gitploy': { | |
'handlers': ['file'], | |
'level': 'DEBUG', | |
'propagate': True | |
} | |
}, | |
# you can also shortcut 'loggers' and just configure logging for EVERYTHING at once | |
'root': { | |
'handlers': ['file', 'console', 'mail_admins'], | |
'level': 'DEBUG', | |
'propagate': True | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is an extract for include the production settings file into normal settings file | |
# place this on the bottom to your settingy.py | |
try: | |
from settings_prod import * | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment