forked from daisyUniverse/TwitFix
-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
vxlogging.py
47 lines (41 loc) · 1.16 KB
/
vxlogging.py
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
IS_DEBUG = False
from flask import request
from io import StringIO
import traceback
def generic(message):
invocation_id = None
try:
if 'serverless.context' in request.environ:
invocation_id = request.environ['serverless.context'].aws_request_id
except:
pass
if invocation_id is None:
invocation_id = ""
else:
invocation_id = str(invocation_id)+" "
message = str(f"{invocation_id}{message}")
print(message)
def info(message):
message = str(message)
generic(f" > [ I ] {message}")
def success(message):
message = str(message)
generic(f" > [ ✔ ] {message}")
def error(message):
message = str(message)
generic(f" > [ ✘ ] {message}")
def warn(message):
message = str(message)
generic(f" > [ ! ] {message}")
def debug(message):
if IS_DEBUG:
message = str(message)
generic(f" > [ D ] {message}")
def get_exception_traceback_str(exc: Exception) -> str:
# Ref: https://stackoverflow.com/a/76584117/
try:
file = StringIO()
traceback.print_exception(exc, file=file)
return file.getvalue().rstrip()
except:
return str(exc)