forked from stackify/stackify-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.py
More file actions
57 lines (44 loc) · 1.6 KB
/
log.py
File metadata and controls
57 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import logging
from stackify.formats import JSONObject
from stackify import MAX_BATCH, LOGGING_LEVELS
from stackify.error import StackifyError
# this is used to separate builtin keys from user-specified keys
RECORD_VARS = set(logging.LogRecord('', '', '', '',
'', '', '', '').__dict__.keys())
# the "message" attribute is saved on the record object by a Formatter
RECORD_VARS.add('message')
class LogMsg(JSONObject):
def __init__(self):
self.Msg = None
self.data = None
self.Ex = None # a StackifyError object
self.Th = None
self.EpochMs = None
self.Level = None
self.TransID = None
self.SrcMethod = None
self.SrcLine = None
def from_record(self, record):
self.Msg = record.getMessage()
self.Th = record.threadName or record.thread
self.EpochMs = int(record.created * 1000)
self.Level = record.levelname
self.SrcMethod = record.funcName
self.SrcLine = record.lineno
# check for user-specified keys
data = {k: v for k, v in record.__dict__.items()
if k not in RECORD_VARS}
if data:
self.data = json.dumps(data, default=lambda x: x.__dict__)
if record.exc_info:
self.Ex = StackifyError()
self.Ex.from_record(record)
class LogMsgGroup(JSONObject):
def __init__(self, msgs, logger=None):
self.Logger = logger or __name__
self.Msgs = msgs
self.CDID = None
self.CDAppID = None
self.AppNameID = None
self.ServerName = None