[solved] Two separate Log files
If you use more than one logger in an experiment, is it possible to have two separate log files instead of having one chaotic log file?
If you use more than one logger in an experiment, is it possible to have two separate log files instead of having one chaotic log file?
Comments
Hi Vivi,
No, I'm afraid not. If you want to maintain a separate log-file, you have to use a bit of inline code. Nothing terribly complicated though.
At the start of the experiment, open the logfile like this:
global myLog myLog = open('mylog.tsv', 'w')At the end of each trial, log responses (or any arbitrary string) like this. The chr(10) is an end of line.
global myLog myLog.write(str(self.get('response')) + chr(10))At the end of the experiment, close the logfile:
Of course, you can handle custom log-files in a ton of ways. This is just an example. For more info about Python file objects, see http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files
Hope this helps!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks, Sebastiaan. That does help. Except, now I have one issue. It is logging each response twice. Why is that?
EDIT: Solved. It is interesting how you can play around with all of the scripts and can figure out what is wrong. I had input the script in both the prepare and the run phases.
Also, in the inline script, is there a way to designate in the file name a subject number which automatically changes for every new subject I run? Or would I have to go into the inline script and add a number in my file name every time I run the experiment with a different subject?
Sure, you can access the subject number as the subject_nr variable. (also see this post)
So you can create a filename that the depends on the subject nr like this:
global myLog myLog = open('mylog-%d.tsv' % self.get('subject_nr'), 'w')Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you, Sebastiaan. Everything works well now.