-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.py
31 lines (23 loc) · 841 Bytes
/
log.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
import logging
import json
# logging.basicConfig(format="%(message)s", level=logging.DEBUG)
logging.basicConfig(format="%(message)s", level=logging.INFO)
# disable http request logging
# to avoid logging health checks
log = logging.getLogger("werkzeug")
log.setLevel(logging.ERROR)
def debug(obj):
"""log object as json if in debug mode"""
if logging.getLogger().level == logging.DEBUG:
logging.debug(json.dumps(obj, indent=2, default=str))
def info(obj):
"""log object as json if in info mode"""
if logging.getLogger().level == logging.INFO:
logging.info(json.dumps(obj, indent=2, default=str))
def llm(input, output):
"""log llm calls to stdout using specific format"""
payload = {
"input": input,
"output": output
}
print(f"LLM: {json.dumps(payload, default=str)}")