Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Two separate Log files

edited April 2012 in OpenSesame

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

  • edited 8:31PM

    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:

    global myLog
    myLog.close()

    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

  • edited April 2012

    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.

  • edited 8:31PM

    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?

  • edited 8:31PM
    is there a way to designate in the file name a subject number which automatically changes for every new subject I run?

    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!

  • edited 8:31PM

    Thank you, Sebastiaan. Everything works well now.

Sign In or Register to comment.