Browse Source

log configuration values taken from the .ini files

Damien ACCORSI 10 years ago
parent
commit
5f62e2decc
1 changed files with 31 additions and 0 deletions
  1. 31 0
      tracim/tracim/config/app_cfg.py

+ 31 - 0
tracim/tracim/config/app_cfg.py View File

@@ -176,6 +176,22 @@ class CFG(object):
176 176
             CFG._instance = CFG()
177 177
         return CFG._instance
178 178
 
179
+    def __setattr__(self, key, value):
180
+        """
181
+        Log-ready setter. this is used for logging configuration (every parameter except password)
182
+        :param key:
183
+        :param value:
184
+        :return:
185
+        """
186
+        if 'PASSWORD' not in key and 'URL' not in key and 'CONTENT' not in key:
187
+            # We do not show PASSWORD for security reason
188
+            # we do not show URL because the associated config uses tg.lurl() which is evaluated when at display time.
189
+            # At the time of configuration setup, it can't be evaluated
190
+            # We do not show CONTENT in order not to pollute log files
191
+            logger.info(self, 'CONFIG: [ {} | {} ]'.format(key, value))
192
+
193
+        self.__dict__[key] = value
194
+
179 195
     def __init__(self):
180 196
         self.WEBSITE_TITLE = tg.config.get('website.title', 'TRACIM')
181 197
         self.WEBSITE_HOME_TITLE_COLOR = tg.config.get('website.title.color', '#555')
@@ -200,6 +216,21 @@ class CFG(object):
200 216
         self.EMAIL_NOTIFICATION_SMTP_USER = tg.config.get('email.notification.smtp.user')
201 217
         self.EMAIL_NOTIFICATION_SMTP_PASSWORD = tg.config.get('email.notification.smtp.password')
202 218
 
219
+        self.TRACKER_JS_PATH = tg.config.get('js_tracker_path')
220
+        self.TRACKER_JS_CONTENT = self.get_tracker_js_content(self.TRACKER_JS_PATH)
221
+
222
+
223
+    def get_tracker_js_content(self, js_tracker_file_path = None):
224
+        js_tracker_file_path = tg.config.get('js_tracker_path', None)
225
+        if js_tracker_file_path:
226
+            logger.info(self, 'Reading JS tracking code from file {}'.format(js_tracker_file_path))
227
+            with open (js_tracker_file_path, 'r') as js_file:
228
+                data = js_file.read()
229
+            return data
230
+        else:
231
+            return ''
232
+
233
+
203 234
 
204 235
     class CST(object):
205 236
         ASYNC = 'ASYNC'