psychopy.logging
- control what gets logged¶Provides functions for logging error and other messages to one or more files and/or the console, using python’s own logging module. Some warning messages and error messages are generated by PsychoPy itself. The user can generate more using the functions in this module.
There are various levels for logged messages with the following order of importance: ERROR, WARNING, DATA, EXP, INFO and DEBUG.
When setting the level for a particular log target (e.g. LogFile) the user can set the minimum level that is required for messages to enter the log. For example, setting a level of INFO will result in INFO, EXP, DATA, WARNING and ERROR messages to be recorded but not DEBUG messages.
By default, PsychoPy will record messages of WARNING level and above to the console. The user can silence that by setting it to receive only CRITICAL messages, (which PsychoPy doesn’t use) using the commands:
from psychopy import logging
logging.console.setLevel(logging.CRITICAL)
A text stream to receive inputs from the logging system
Create a log file as a target for logged entries of a given level
this could be a string to a path, that will be created if it doesn’t exist. Alternatively this could be a file object, sys.stdout or any object that supports .write() and .flush() methods
The minimum level of importance that a message must have to be logged by this target.
Append or overwrite existing log file
Maintains a set of log targets (text streams such as files of stdout)
self.targets is a list of dicts {‘stream’:stream, ‘level’:level}
The string-formatted elements {xxxx} can be used, where each xxxx is an attribute of the LogEntry. e.g. t, t_ms, level, levelname, message
Associate ‘levelName’ with ‘level’.
This is used when converting levels to text during message formatting.
Send the message to any receiver of logging info (e.g. a LogFile) of level log.CRITICAL or higher
Log a message about data collection (e.g. a key press)
log.data(message)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.DATA or higher
Log a debugging message (not likely to be wanted once experiment is finalised)
log.debug(message)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.DEBUG or higher
Send the message to any receiver of logging info (e.g. a LogFile) of level log.ERROR or higher
Log a message about the experiment (e.g. a new trial, or end of a stimulus)
log.exp(message)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.EXP or higher
log.critical(message) Send the message to any receiver of logging info (e.g. a LogFile) of level log.CRITICAL or higher
Send current messages in the log to all targets
Return the textual representation of logging level ‘level’.
If the level is one of the predefined levels (CRITICAL, ERROR, WARNING, INFO, DEBUG) then you get the corresponding string. If you have associated levels with names using addLevelName then the name you have associated with ‘level’ is returned.
If a numeric value corresponding to one of the defined levels is passed in, the corresponding string representation is returned.
Otherwise, the string “Level %s” % level is returned.
Log some information - maybe useful, maybe not
log.info(message)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.INFO or higher
Log a message
log(msg, level, t=t, obj=obj)
Log the msg, at a given level on the root logger
Set the default clock to be used to reference all logging times.
Must be a psychopy.core.Clock
object. Beware that if you
reset the clock during the experiment then the resets will be
reflected here. That might be useful if you want your logs to be
reset on each trial, but probably not.
log.warning(message)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.WARNING or higher
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.WARNING or higher
flush()
¶setDefaultClock()
¶Set the default clock to be used to reference all logging times.
Must be a psychopy.core.Clock
object. Beware that if you
reset the clock during the experiment then the resets will be
reflected here. That might be useful if you want your logs to be
reset on each trial, but probably not.