OpenSesame videos
Python videos
Supported by Supported by

Log functions

instance log

The log object provides data logging. A log object is created automatically when the experiment starts.

Example:

# Write one line of text
log.write(u'My custom log message')
# Write all variables
log.write_vars()

function log.close()

Closes the current log.

Example:

log.close()

function log.open(path)

Opens the current log. If a log was already open, it is closed automatically, and re-opened.

Example:

# Open a new log
log.open(u'/path/to/new/logfile.csv')

Arguments:

  • path -- The path to the current logfile. In most cases (unless) a custom log back-end is used, this will be a filename.
    • Type: str, unicode

function log.write(msg, newline=True)

Write one message to the log.

Example:

# Write a single string of text
log.write(u'time = %s' % clock.time())

Arguments:

  • msg -- A text message. When using Python 2, this should be either unicode or a utf-8-encoded str. When using Python 3, this should be either str or a utf-8-encoded bytes.
    • Type: str, unicode

Keywords:

  • newline -- Indicates whether a newline should be written after the message.
    • Type: bool
    • Default: True

function log.write_vars(var_list=None)

Writes variables to the log.

Example:

# Write all variables to the logfile
log.write_vars()

Keywords:

  • var_list -- A list of variable names to write, or None to write all variables that exist in the experiment.
    • Type: list, NoneType
    • Default: None
Supported by Supported by