-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogFiles.py
48 lines (40 loc) · 2.08 KB
/
logFiles.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
48
#!/usr/bin/env python
from psychopy import logging, core, visual
"""PsychoPy's log module is mostly a simple wrapper of the python logging module.
It allows messages to be sent from any location (any library or your script) and
written to files according to the importance level of the message and the minimum level
that the log file (or console) is set to receive. You can have multiple log files each receiving
different levels of input.
The importance levels are;
40:ERROR
35:DATA
30:WARNING
25:DATA
22: EXP
20:INFO
10:DEBUG
So setting to DEBUG level will include all possible messages, setting to ERROR will include only the absolutely essential messages.
"""
globalClock = core.Clock()#if this isn't provided the log times will reflect secs since python started
logging.setDefaultClock(globalClock)#use this for
logging.console.setLevel(logging.DEBUG)#set the console to receive nearly all messges
logDat = logging.LogFile('logLastRun.log',
filemode='w',#if you set this to 'a' it will append instead of overwriting
level=logging.WARNING)#errors, data and warnings will be sent to this logfile
#the following will go to any files with the appropriate minimum level set
logging.info('Something fairly unimportant')
logging.data('Something about our data. Data is likely very important!')
logging.warning('Handy while building your experiment - highlights possible flaws in code/design')
logging.error("You might have done something that PsychoPy can't handle! But hopefully this gives you some idea what.")
#some things should be logged timestamped on the next video frame
#For instance the time of a stimulus appearing is related to the flip:
win = visual.Window([400,400])
for n in range(5):
win.logOnFlip('frame %i occured' %n, level=logging.EXP)
if n in [2,4]:
win.logOnFlip('an even frame occured', level=logging.EXP)
win.flip()
#LogFiles can also simply receive direct input from the write() method
#messages using write() will be sent immediately, and are often not
#in correct chronological order with logged messages
logDat.write("Testing\n\n")