1- import logging
1+ import os
22from pathlib import Path
33
4- BOT_PROJECT_NAME = '{{ bot_project_name }} '
4+ BOT_PROJECT_NAME = 'bot '
55
6- BOT_CONTEXT_CONFIGURATION = '{{ bot_project_name }} .configuration.context'
6+ BOT_CONTEXT_CONFIGURATION = 'bot .configuration.context'
77
8- BASE_DIR = str(Path(__file__).parent)
8+ # Change this when not in development, feature or hot-fix branch
9+ DEBUG = int(os.environ.get('DEBUG', True))
910
10- LOG_PATH = BASE_DIR
11+ BASE_DIR = str(Path(__file__).parent.parent)
1112
1213LOG_FILE_NAME = 'log'
1314
14- # Logger configuration
15- logging.basicConfig(level=logging.INFO)
16- logFormatter = logging.Formatter("%(asctime)s [%(threadName)] [%(levelname)] %(message)s")
17- rootLogger = logging.getLogger()
18-
19- fileHandler = logging.FileHandler("{0}/{1}.log".format(LOG_PATH, LOG_FILE_NAME))
20- fileHandler.setFormatter(logFormatter)
21- rootLogger.addHandler(fileHandler)
22-
23- consoleHandler = logging.StreamHandler()
24- consoleHandler.setFormatter(logFormatter)
25- rootLogger.addHandler(consoleHandler)
15+ LOG_PATH = "{}{}.log".format(BASE_DIR, LOG_FILE_NAME)
16+
17+ if DEBUG:
18+ logging_level = "DEBUG"
19+ else:
20+ logging_level = "INFO"
21+
22+ # Logging configuration
23+ LOGGING = {
24+ 'version': 1,
25+ 'disable_existing_loggers': False,
26+ 'formatters': {
27+ 'standard': {
28+ 'format': '%(levelname)s %(asctime)s - [thread: %(threadName)-4s %(name)s] %(message)s',
29+ 'datefmt': '%Y-%m-%d %H:%M:%S'
30+ }
31+ },
32+ 'handlers': {
33+ 'console': {
34+ 'class': 'logging.StreamHandler',
35+ 'formatter': 'standard',
36+ },
37+ 'file': {
38+ 'formatter': 'standard',
39+ 'class': 'logging.handlers.RotatingFileHandler',
40+ 'filename': LOG_PATH,
41+ 'backupCount': 10,
42+ 'maxBytes': 10000,
43+ },
44+ },
45+ 'loggers': {
46+ '': {
47+ 'level': logging_level,
48+ 'handlers': ['console', 'file'],
49+ },
50+ },
51+ }
0 commit comments