Dirk Alders 3 years ago
parent
commit
25889f225b
3 changed files with 2163 additions and 2135 deletions
  1. 29
    16
      __init__.py
  2. 2134
    2119
      _testresults_/unittest.json
  3. BIN
      _testresults_/unittest.pdf

+ 29
- 16
__init__.py View File

29
 __DEPENDENCIES__ = []
29
 __DEPENDENCIES__ = []
30
 
30
 
31
 import collections
31
 import collections
32
+import json
32
 import logging
33
 import logging
33
 from logging.config import dictConfig
34
 from logging.config import dictConfig
34
 import os
35
 import os
35
 import sys
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
 __DESCRIPTION__ = """The Module {\\tt %s} is designed to help with python logging and to support some handlers for logging to memory.
44
 __DESCRIPTION__ = """The Module {\\tt %s} is designed to help with python logging and to support some handlers for logging to memory.
41
 For more Information read the sphinx documentation.""" % __name__.replace('_', '\_')
45
 For more Information read the sphinx documentation.""" % __name__.replace('_', '\_')
151
         self.MY_LOGS.append(record.__dict__)
155
         self.MY_LOGS.append(record.__dict__)
152
         self.MY_LOGS[-1]['moduleLogger'] = collectingHandler().get_logs()
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
     target_handlers = ['main', ]
169
     target_handlers = ['main', ]
156
-    if basepath is not None:
157
-        target_handlers.append('logwarn')
158
     # define handler
170
     # define handler
159
     #
171
     #
160
     if target == 'stdout':
172
     if target == 'stdout':
167
     elif target == 'logfile':
179
     elif target == 'logfile':
168
         handler = dict(main={
180
         handler = dict(main={
169
             'level': 'DEBUG',
181
             'level': 'DEBUG',
170
-            'formatter': 'format',
182
+            'formatter': 'json',
171
             'class': 'logging.handlers.RotatingFileHandler',
183
             'class': 'logging.handlers.RotatingFileHandler',
172
             'filename': os.path.join(basepath, 'messages.log'),
184
             'filename': os.path.join(basepath, 'messages.log'),
173
             'mode': 'a',
185
             'mode': 'a',
180
             'formatter': 'my_format',
192
             'formatter': 'my_format',
181
             'class': 'logging.NullHandler',
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
     if ring_logs is not None:
203
     if ring_logs is not None:
184
         target_handlers.append('ring')
204
         target_handlers.append('ring')
185
         handler['ring'] = {
205
         handler['ring'] = {
186
             'class': 'report.collectingRingHandler',
206
             'class': 'report.collectingRingHandler',
187
             'max_logs': ring_logs,
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
     # define loggers
209
     # define loggers
200
     #
210
     #
201
     loggers = {}
211
     loggers = {}
210
     dictConfig(dict(
220
     dictConfig(dict(
211
         version=1,
221
         version=1,
212
         formatters={
222
         formatters={
223
+            'json': {
224
+                '()': JsonFormatter
225
+            },
213
             'long': {
226
             'long': {
214
                 'format': LONG_FMT
227
                 'format': LONG_FMT
215
             },
228
             },

+ 2134
- 2119
_testresults_/unittest.json
File diff suppressed because it is too large
View File


BIN
_testresults_/unittest.pdf View File


Loading…
Cancel
Save