-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_logging.py
More file actions
38 lines (32 loc) · 1.05 KB
/
_logging.py
File metadata and controls
38 lines (32 loc) · 1.05 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
import logging
from datetime import datetime, timezone
class LogHandlerSumo(logging.Handler):
def __init__(self, sumo_client):
logging.Handler.__init__(self)
self._sumoClient = sumo_client
return
def emit(self, record):
try:
dt = (
datetime.now(timezone.utc)
.replace(microsecond=0, tzinfo=None)
.isoformat()
+ "Z"
)
json = {
"severity": record.levelname,
"message": record.getMessage(),
"timestamp": dt,
"source": record.name,
"pathname": record.pathname,
"funcname": record.funcName,
"linenumber": record.lineno,
}
if "objectUuid" in record.__dict__:
json["objectUuid"] = record.__dict__.get("objectUuid")
self._sumoClient.post("/message-log/new", json=json)
except Exception:
# Never fail on logging
pass
return
pass