psychopy.org | Reference | Downloads | Github

Turning off all logging

Did the default logging change with Psychopy 1.90? It seems that if I get an error now, I automatically get all the logging messages (unclear from where) dumped to the console which prevents me from seeing the error. Anyone know how to turn them off?

Thanks!

The logging messages look like this:

|9.4547 |EXP |Created unnamed ImageStim = ImageStim(autoLog=True, color=array([ 1.,  1.,  1.]), colorSpace='rgb', contrast=1.0, depth=0, flipHoriz=False, flipVert=False, image=str(...), interpolate=True, mask=None, maskParams=None, name='unnamed ImageStim', opacity=1.0, ori=0.0, pos=array([ 0.,  0.]), size=array([500, 500]), texRes=128, units='pix', win=Window(...))|
|---|---|---|
|9.4663 |EXP |Created unnamed ImageStim = ImageStim(autoLog=True, color=array([ 1.,  1.,  1.]), colorSpace='rgb', contrast=1.0, depth=0, flipHoriz=False, flipVert=False, image=str(...), interpolate=True, mask=None, maskParams=None, name='unnamed ImageStim', opacity=1.0, ori=0.0, po|

29.6711 	EXP 	Created unnamed Rect = Rect(autoDraw=False, autoLog=True, closeShape=True, contrast=1.0, depth=0, fillColor='white', fillColorSpace='named', fillRGB=array([ 255.,  255.,  255.]), interpolate=True, lineColor='black', lineColorSpace='named', lineRGB=array([ 0.,  0.,  0.]), lineWidth=3, name='unnamed Rect', opacity=1.0, ori=array(0.0), pos=array([ 0.,  0.]), size=array([ 1040.,  1040.]), units='pix', vertices=ndarray(...), win=Window(...))
30.6888 	EXP 	<method-wrapper '__getattribute__' of attributeSetter object at 0x10c48f410>: vertices = array([[-0.25,  0.25],
       [ 0.25,  0.25],
       [ 0.25, -0.25],
       [-0.25, -0.25]])
30.6897 	EXP 	Created unnamed Rect = Rect(autoDraw=False, autoLog=True, closeShape=True, contrast=1.0, depth=0, fillColor='white', fillColorSpace='named', fillRGB=array([ 255.,  255.,  255.]), interpolate=True, lineColor='black', lineColorSpace='named', lineRGB=array([ 0.,  0.,  0.]), lineWidth=3, name='unnamed Rect', opacity=1.0, ori=array(0.0), pos=array([ 0.,  0.]), size=array([ 1040.,  1040.]), units='pix', vertices=ndarray(...), win=Window(...))
30.8399 	EXP 	<method-wrapper '__getattribute__' of attributeSetter object at 0x10c48f410>: vertices = array([[-0.25,  0.25],
       [ 0.25,  0.25],
       [ 0.25, -0.25],
       [-0.25, -0.25]])

Hi,
you can change the log levels in the top of your script to silence unwanted logs.
for example,

from psychopy import logging
logging.console.setLevel(logging.WARNING)

will only print ERROR and WARNING logs to the console

5.6546  WARNING         Requested an unavailable screen number - using first available.
5.6547  WARNING         User requested fullscreen with size [1280 1024], but screen is actually [1920, 1080]. Using actual size
6.6479  WARNING         ExperimentHandler created with no dataFileName parameter. No data will be saved in the event of a crash

You can check this page for more information!

1 Like

Thanks - Even when set to log warning (or logging.CRITICAL), I am still getting all the logs (e.g., info on every stimulus that’s loaded) being output to standard out, but only when the experiment quits, either because of an error, or if I do it with Ctrl-C.

It appears this behavior is new as of 1.90.1 (and remains in 1.90.2).

I tried to terminate the script with Ctrl-C, but I did not get all the infos. Neither did I get the infos when an error occurs.
I’m using 1.90.2 in Python 3, can it be the version of Python cause the problem?

Python 2.7.13 I can try it with a virtual env Python3. If you have Python 2.7 installed, can you give it a try?

I tested the same script with both 1.85.3 and 1.90.2 on Python 2.7.14 and only got WARNING logs.
I only get all the infos (e.g., EXP logs) when I removed the declaration of logging level.

EDIT
I replicated the problem by changing the import order of logging module.
When my script was written like the following, I will get all the logs.

# -*- coding: utf-8 -*-
from psychopy import logging
logging.console.setLevel(logging.WARNING)
from psychopy import visual
from psychopy import core
from psychopy import prefs
prefs.general['audioLib'] = ['sounddevice']
from psychopy import event
from psychopy import sound
from psychopy import data

# This will print all the logs

However, if the logging module was imported after other modules from PsychoPy, it worked as expected.

# -*- coding: utf-8 -*-
from psychopy import visual
from psychopy import core
from psychopy import prefs
prefs.general['audioLib'] = ['sounddevice']
from psychopy import event
from psychopy import sound
from psychopy import data
from psychopy import logging
logging.console.setLevel(logging.WARNING)

# This will only print WARNING and ERROR logs

Can you try changing the order of logging module and see if that solves the problem?

Hi,

One important thing: you are not using a appropriate coding style.
Keep the import statements and code apart from eachother.
It is possible that other modules set the logging level to a lower value after you’ve set a logging level.
The Python style guide can be found here: https://www.python.org/dev/peps/pep-0008/