Dirk Alders 4 anni fa
parent
commit
25889f225b
3 ha cambiato i file con 2163 aggiunte e 2135 eliminazioni
  1. 29
    16
      __init__.py
  2. 2134
    2119
      _testresults_/unittest.json
  3. BIN
      _testresults_/unittest.pdf

+ 29
- 16
__init__.py Vedi File

@@ -29,13 +29,17 @@ report (Report Module)
29 29
 __DEPENDENCIES__ = []
30 30
 
31 31
 import collections
32
+import json
32 33
 import logging
33 34
 from logging.config import dictConfig
34 35
 import os
35 36
 import sys
36 37
 
37
-logger_name = 'REPORT'
38
-logger = logging.getLogger(logger_name)
38
+try:
39
+    from config import APP_NAME as ROOT_LOGGER_NAME
40
+except ImportError:
41
+    ROOT_LOGGER_NAME = 'root'
42
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
39 43
 
40 44
 __DESCRIPTION__ = """The Module {\\tt %s} is designed to help with python logging and to support some handlers for logging to memory.
41 45
 For more Information read the sphinx documentation.""" % __name__.replace('_', '\_')
@@ -151,10 +155,18 @@ class collectingTestcaseHandler(collectingHandler):
151 155
         self.MY_LOGS.append(record.__dict__)
152 156
         self.MY_LOGS[-1]['moduleLogger'] = collectingHandler().get_logs()
153 157
 
154
-def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_logs=None):
158
+
159
+class JsonFormatter(logging.Formatter):
160
+    def format(self, record):
161
+        obj = {}
162
+        for key in ["name", "levelno", "levelname", "pathname", "filename", "module", "lineno", "funcName", "created", "msecs", "relativeCreated", "thread", "threadName", "process", "processName", "msg", "args", "exc_info", "exc_text"]:
163
+            obj[key] = getattr(record, key)
164
+        obj["msg"] = obj["msg"] % obj["args"]
165
+        return json.dumps(obj)
166
+
167
+
168
+def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_logs=None, host=None, port=None):
155 169
     target_handlers = ['main', ]
156
-    if basepath is not None:
157
-        target_handlers.append('logwarn')
158 170
     # define handler
159 171
     #
160 172
     if target == 'stdout':
@@ -167,7 +179,7 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
167 179
     elif target == 'logfile':
168 180
         handler = dict(main={
169 181
             'level': 'DEBUG',
170
-            'formatter': 'format',
182
+            'formatter': 'json',
171 183
             'class': 'logging.handlers.RotatingFileHandler',
172 184
             'filename': os.path.join(basepath, 'messages.log'),
173 185
             'mode': 'a',
@@ -180,22 +192,20 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
180 192
             'formatter': 'my_format',
181 193
             'class': 'logging.NullHandler',
182 194
         })
195
+    if host is not None and port is not None:
196
+        target_handlers.append('socket')
197
+        handler['socket']={
198
+            'level': 'DEBUG',
199
+            'class': 'logging.handlers.SocketHandler',
200
+            'host': host,
201
+            'port': port
202
+        }
183 203
     if ring_logs is not None:
184 204
         target_handlers.append('ring')
185 205
         handler['ring'] = {
186 206
             'class': 'report.collectingRingHandler',
187 207
             'max_logs': ring_logs,
188 208
         }
189
-    if basepath is not None:
190
-        handler['logwarn'] = {
191
-            'level': 'WARNING',
192
-            'formatter': 'long',
193
-            'class': 'logging.handlers.RotatingFileHandler',
194
-            'filename': os.path.join(basepath, 'messages.warn'),
195
-            'mode': 'a',
196
-            'maxBytes': 10485760,
197
-             'backupCount': 2
198
-        }
199 209
     # define loggers
200 210
     #
201 211
     loggers = {}
@@ -210,6 +220,9 @@ def appLoggingConfigure(basepath, target, log_name_lvl=[], fmt=SHORT_FMT, ring_l
210 220
     dictConfig(dict(
211 221
         version=1,
212 222
         formatters={
223
+            'json': {
224
+                '()': JsonFormatter
225
+            },
213 226
             'long': {
214 227
                 'format': LONG_FMT
215 228
             },

+ 2134
- 2119
_testresults_/unittest.json
File diff soppresso perché troppo grande
Vedi File


BIN
_testresults_/unittest.pdf Vedi File


Loading…
Annulla
Salva