Ubuntu
commited on
Commit
·
034cfa9
1
Parent(s):
fae2553
axiom logger
Browse files- axiom_logger.py +66 -0
axiom_logger.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import axiom
|
2 |
+
from datetime import datetime,timedelta
|
3 |
+
import rfc3339
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import os
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
class AxiomLogger:
|
10 |
+
|
11 |
+
def __init__(self):
|
12 |
+
load_dotenv()
|
13 |
+
api_token = os.getenv('AXIOM_API_KEY')
|
14 |
+
org_id = os.getenv('AXIOM_ORG_ID')
|
15 |
+
self.client = axiom.Client(api_token, org_id)
|
16 |
+
self.dataset='sdxl-server'
|
17 |
+
|
18 |
+
def get_timestamp_formatted(self):
|
19 |
+
time = datetime.utcnow()
|
20 |
+
time_formatted = rfc3339.format(time)
|
21 |
+
return time_formatted
|
22 |
+
|
23 |
+
def ingest_with_status(self, status, message, **kwargs):
|
24 |
+
self.client.ingest_events(
|
25 |
+
dataset=self.dataset,
|
26 |
+
events=[{
|
27 |
+
"_time": self.get_timestamp_formatted(),
|
28 |
+
"status": status,
|
29 |
+
"message": message,
|
30 |
+
**kwargs
|
31 |
+
}])
|
32 |
+
|
33 |
+
def warning(self, message, **kwargs):
|
34 |
+
self.ingest_with_status("WARNING", message, **kwargs)
|
35 |
+
|
36 |
+
def error(self, message, **kwargs):
|
37 |
+
self.ingest_with_status("ERROR", message, **kwargs)
|
38 |
+
|
39 |
+
def info(self, message, **kwargs):
|
40 |
+
self.ingest_with_status("INFO", message, **kwargs)
|
41 |
+
|
42 |
+
def debug(self, message, **kwargs):
|
43 |
+
self.ingest_with_status("DEBUG", message, **kwargs)
|
44 |
+
|
45 |
+
def critical(self, message, **kwargs):
|
46 |
+
self.ingest_with_status("CRITICAL", message, **kwargs)
|
47 |
+
|
48 |
+
|
49 |
+
def main():
|
50 |
+
api_token = os.getenv('AXIOM_API_KEY')
|
51 |
+
org_id = os.getenv('AXIOM_ORG_ID')
|
52 |
+
client = axiom.Client(api_token, org_id)
|
53 |
+
|
54 |
+
time = datetime.utcnow() - timedelta(hours=1)
|
55 |
+
time_formatted = rfc3339.format(time)
|
56 |
+
|
57 |
+
client.ingest_events(
|
58 |
+
dataset="sdxl-server",
|
59 |
+
events=[
|
60 |
+
{"inference_test": "test1", "_time": time_formatted},
|
61 |
+
{"inference_test": "test2", "_time": time_formatted},
|
62 |
+
])
|
63 |
+
|
64 |
+
|
65 |
+
if __name__=='__main__':
|
66 |
+
main()
|