[open] switching between two log files
Hi everyone,
Background:
I'm finishing up an experiment that investigates the effect of masked and unmasked cues. I'm already logging the experiment-related variables, like response_time
, variables defined in loops, inline-script variables, etc. Tracking presentation timing is important to us, so I've started to log most of the time_
variables as well. Unfortunately, this is starting to make the log files very unwieldy. To simplify the files, I'd like to split log file into two separate log files -- one .csv where all the timing data will be recorded (which I will only sometimes use), another .csv where all the all experiment variables will be recorded (which I will always use).
Tl;dr question:
What I'd like to do is have two loggers and create two log files. At the conclusion of a trial sequence in my loop, I'd like to have logger #1 write to file #1, then logger #2 write to file #2. Then repeat across trials.
I'm not sure how to do this. I've been working with a mini-experiment to test out various things:
Here's the content of makePaths
at the start of the experiment:
location = 'uci'
path_time = 'time_' + location + '_' + str(self.get('subject_nr')) + '.csv'
path_vars = 'vars_' + location + '_' + str(self.get('subject_nr')) + '.csv'
I've looked through the forum and found a lot of code like this:
import os
#close current logfile
exp._log.close()
#set new path
exp.logfile = path_NAME
#open new logfile
exp._log = None
exp.init_log()
so I've been working with this code in each setPath_
script (setPath_time
uses path_time
where path_NAME
is, etc.).
If I run this as written above, then I only get information in the vars_uci_0.csv
file, and only for the last trial. I've tried commenting out various lines in the setPath_
scripts, but can't get the functionality I'm looking for.
I need to find a way to leave both files open always, and just have the the loggers flexibly switch which file they're writing to. No idea how to do that though, if it's possible.
I appreciate any help you guys can provide!
--beth
(Also: I know I could use python to open two files, then write to each of them in turn, etc. However, with the number of variables I'd like to record, I think this would be a frustrating option.)
Comments
Hi Beth,
That's an interesting question. What you could do is hack into the OpenSesame internals, and replace the
logger
'slog()
function by your own function. Let's assume that your logger is called custom_logger, then you could this as follows (at the beginning of the experiment):Next, it would be a matter if implementing
my_custom_log()
such that it writes the data to the file of your choosing.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!