-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_log.py
More file actions
executable file
·45 lines (35 loc) · 1.02 KB
/
text_log.py
File metadata and controls
executable file
·45 lines (35 loc) · 1.02 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
39
40
41
42
43
44
45
#Joe Snider
#2/12
#
#Mimic a simple sensor that can act as a log file
class TextLog:
#can send in some initial data (e.g. a header)
# be sure to put a newline on the initial if desired
def __init__(self, initial=""):
self.initial = initial
self.dumpStr = ""
#the trials thing is for compatability with the logger
def startRecording(self, trials=0):
self.clearRecording()
def stopRecording(self, junk=0):
pass
#dump the recorded data to the file fileName
def dumpRecording(self, fileName):
fil = open(fileName, 'w')
fil.write(self.initial)
fil.write(self.dumpStr)
self.dumpStr = ""
def clearRecording(self):
self.dumpStr = ""
#add something to the log (newlines etc.. are your resp.)
def Record(self, data):
self.dumpStr += data
if __name__ == "__main__":
import logutil
Tl = TextLog("asdf sadf sewr\n")
logger = logutil.TrialLogger()
logger.addSimpleSensor(Tl, 'event_log', 100)
logger.startTrial()
Tl.Record("%g %d %d\n"%(1.123, 3, 5))
Tl.Record("whatever I want")
logger.stopTrial()