Skip to content

Commit d28e60b

Browse files
committed
Add settings configuration for logging
1 parent 5affedb commit d28e60b

File tree

1 file changed

+43
-17
lines changed
  • investing_bot_framework/templates/bot_project_directory/bot_project_template/configuration

1 file changed

+43
-17
lines changed
Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1-
import logging
1+
import os
22
from 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

1213
LOG_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

Comments
 (0)