Implement Logging and Pathlib
This commit is contained in:
parent
7294638493
commit
a20fba656a
@ -1,6 +1,7 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
import os, environ
|
import os, environ
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
env = environ.Env(
|
env = environ.Env(
|
||||||
# set casting, default value
|
# set casting, default value
|
||||||
@ -8,11 +9,12 @@ env = environ.Env(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
# BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
BASE_DIR = Path(__file__).parent.parent
|
||||||
CORE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
CORE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
# Take environment variables from .env file
|
# Take environment variables from .env file
|
||||||
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))
|
environ.Env.read_env(BASE_DIR / ".env")
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = env('SECRET_KEY', default='S#perS3crEt_007')
|
SECRET_KEY = env('SECRET_KEY', default='S#perS3crEt_007')
|
||||||
@ -117,6 +119,34 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Loggiong
|
||||||
|
|
||||||
|
LOGGING_DIR = BASE_DIR / "logs"
|
||||||
|
LOGGING_DIR.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
LOGGING = {
|
||||||
|
'version': 1,
|
||||||
|
'disable_existing_loggers': False,
|
||||||
|
'handlers': {
|
||||||
|
'file': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.FileHandler',
|
||||||
|
'filename': LOGGING_DIR / 'debug.log',
|
||||||
|
},
|
||||||
|
'console': {
|
||||||
|
'level': 'DEBUG',
|
||||||
|
'class': 'logging.StreamHandler',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'loggers': {
|
||||||
|
'django': {
|
||||||
|
'handlers': ['file', 'console'],
|
||||||
|
'level': 'INFO',
|
||||||
|
'propagate': True,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user