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)
psychopy.logging.
LogFile
(f=None, level=30, filemode='a', logger=None, encoding='utf8')¶A text stream to receive inputs from the logging system
Create a log file as a target for logged entries of a given level
Parameters: |
|
---|
setLevel
(level)¶Set a new minimal level for the log file/stream
write
(txt)¶Write directy to the log file (without using logging functions). Useful to send messages that only this file receives
psychopy.logging.
addLevel
(level, levelName)¶Associate ‘levelName’ with ‘level’.
This is used when converting levels to text during message formatting.
psychopy.logging.
critical
(message)¶Send the message to any receiver of logging info (e.g. a LogFile) of level log.CRITICAL or higher
psychopy.logging.
data
(msg, t=None, obj=None)¶Log a message about data collection (e.g. a key press)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.DATA or higher
psychopy.logging.
debug
(msg, t=None, obj=None)¶Log a debugging message (not likely to be wanted once experiment is finalised)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.DEBUG or higher
psychopy.logging.
error
(message)¶Send the message to any receiver of logging info (e.g. a LogFile) of level log.ERROR or higher
psychopy.logging.
exp
(msg, t=None, obj=None)¶Log a message about the experiment (e.g. a new trial, or end of a stimulus)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.EXP or higher
psychopy.logging.
fatal
(msg, t=None, obj=None)¶log.critical(message) Send the message to any receiver of logging info (e.g. a LogFile) of level log.CRITICAL or higher
psychopy.logging.
flush
(logger=<psychopy.logging._Logger object at 0x061DBE50>)¶Send current messages in the log to all targets
psychopy.logging.
getLevel
(level)¶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.
psychopy.logging.
info
(msg, t=None, obj=None)¶Log some information - maybe useful, maybe not
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.INFO or higher
psychopy.logging.
log
(msg, level, t=None, obj=None)¶Log a message
Log the msg, at a given level on the root logger
psychopy.logging.
setDefaultClock
(clock)¶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.
psychopy.logging.
warn
(msg, t=None, obj=None)¶log.warning(message)
Sends the message to any receiver of logging info (e.g. a LogFile) of level log.WARNING or higher
psychopy.logging.
warning
(message)¶Sends the message to any receiver of logging info (e.g. a LogFile) of level log.WARNING or higher
flush()
¶psychopy.logging.
flush
(logger=<psychopy.logging._Logger object at 0x061DBE50>)Send current messages in the log to all targets
setDefaultClock()
¶psychopy.logging.
setDefaultClock
(clock)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.