Clémentine commited on
Commit
272ebb9
1 Parent(s): da4c3ac

add logging back

Browse files
Files changed (1) hide show
  1. src/logging.py +32 -0
src/logging.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from src.envs import API
3
+
4
+ class Logger:
5
+ def __init__(self, filename):
6
+ self.terminal = sys.stdout
7
+ self.log = open(filename, "a+")
8
+
9
+ def write(self, message):
10
+ self.terminal.write(message)
11
+ self.log.write(message)
12
+
13
+ def flush(self):
14
+ self.terminal.flush()
15
+ self.log.flush()
16
+
17
+ def isatty(self):
18
+ return False
19
+
20
+ def read_logs():
21
+ sys.stdout.flush()
22
+ #API.upload_file(
23
+ # path_or_fileobj="output.log",
24
+ # path_in_repo="demo-backend.log",
25
+ # repo_id="demo-leaderboard-backend/logs",
26
+ # repo_type="dataset",
27
+ #)
28
+
29
+ with open("output.log", "r") as f:
30
+ return f.read()
31
+
32
+ LOGGER = Logger("output.log")