Supported by Supported by

Log functions

class log

The log provides data logging.

Example:

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

function log.__init__(experiment, path)

Constructor to create a new log object. You do not generally call this constructor directly, because a log object is created automatically when the experiment is launched.

Arguments:

  • experiment -- The exp

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.

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