How to not log text attributes (i.e. height) but everything else in logfile

I am building an experiment showing various text-based stimuli. I noticed that if I toggle save onset/offset times ‘on’, my logfile gets cluttered with messages about the ‘height’ attribute (see below).

I have added a code component that sets autolog to turn off, but I would still like to save onset times for the actual text stimulus shown (also see below).

Is there any way I can just call the text (i.e. “XXX_answer: text” and “XXX_answer: autoDraw = True”) without cluttering my logfile by adding height three times?

16.6869 	EXP 	first_answer: height = 0.05
16.6869 	EXP 	first_answer: height = 0.05
16.6869 	EXP 	first_answer: height = 0.05
16.6869 	EXP 	first_answer: text = 'Sample Text 1 '
16.6869 	EXP 	second_answer: height = 0.05
16.6869 	EXP 	second_answer: height = 0.05
16.6869 	EXP 	second_answer: height = 0.05
16.6869 	EXP 	second_answer: text = 'Sample Text 2'
16.6869 	EXP 	third_answer: height = 0.05
16.6869 	EXP 	third_answer: height = 0.05
16.6869 	EXP 	third_answer: height = 0.05
16.6869 	EXP 	third_answer: text = 'Sample Text 3'
16.6869 	EXP 	fourth_answer: height = 0.05
16.6869 	EXP 	fourth_answer: height = 0.05
16.6869 	EXP 	fourth_answer: height = 0.05
16.6869 	EXP 	fourth_answer: text = 'Sample Text 4'
16.6869 	EXP 	A: height = 0.05
16.6869 	EXP 	A: height = 0.05
16.6869 	EXP 	A: height = 0.05
16.6869 	EXP 	A: text = 'A'
16.6869 	EXP 	first_answer: autoDraw = True
16.6869 	EXP 	second_answer: autoDraw = True
16.6869 	EXP 	third_answer: autoDraw = True
16.6869 	EXP 	fourth_answer: autoDraw = True

Hi,

To achieve this, in the Begin Routine tab of your Code Component, you can try add the following:

def log_text_stimulus(stimulus):
    logging.exp(f"{stimulus.name}: text = '{stimulus.text}'")
    logging.exp(f"{stimulus.name}: autoDraw = {stimulus.autoDraw}")

log_text_stimulus(first_answer)
log_text_stimulus(second_answer)
log_text_stimulus(third_answer)
# ... Continue for other stimuli as needed

With this approach, the function log_text_stimulus will probably ensure that only the desired attributes (text and autoDraw) are logged for each text stimulus.

Hope this helps,

Thomas

Hi Thomas,

thank you very much for your reply! I had found a solution for the text in the meantime, but weren’t able to log the autoDraw times. Your code works in that regard, but I think it just logs the current state of autoDraw and not the actual times that autoDraw is flipped from True to False. Do you maybe have an idea on how to tackle this as well?

Hi,

Thank you for pointing that out. The current code logs the status of autoDraw, not the onset times. To capture these times, consider tracking the previous state of each stimulus autoDraw. By checking this state in each frame and logging any changes with a timestamp, you’ll have an accurate record. Try to insert the following snippet into the ‘Each Frame’ tab of your Code Component. This will log the exact moment each stimulus changes its display status.

# Assuming previous states are initialized to False at the start
try:
    previous_states
except NameError:
    previous_states = {
        'first_answer': False,
        'second_answer': False,
        # ... Add other stimuli names here ...
    }

def check_and_log_autoDraw(stimulus):
    if stimulus.autoDraw != previous_states[stimulus.name]:
        # Logging the time and new state of autoDraw
        logging.exp(f"{stimulus.name}: autoDraw changed to {stimulus.autoDraw} at {globalClock.getTime()}")
        # Update the previous state
        previous_states[stimulus.name] = stimulus.autoDraw

check_and_log_autoDraw(first_answer)
check_and_log_autoDraw(second_answer)
check_and_log_autoDraw(third_answer)
# ... Continue for other stimuli as needed ...

This approach may log the exact times when autoDraw changes state for each stimulus, giving you a clear picture of when each stimulus starts and stops being drawn.

Hope this helps,

Thomas