Extending logging functionality
If you have already adopted some method for logging events, you may want to use that method to log experiment-related events, such as exposures and experiment-specific outcomes. You can do this by extending the
Experiment abstract class and overriding the
To log exposures using your existing logging system, just override the
method when extending the
Experiment abstract class.
For example, if you write to your logs with
MySQLLogger, then you might
log as follows.
def log(self, data): # self.MySQLLogger may be defined here or in configure_logger() self.MySQLLogger.log(data)
Writing a log configuration method
Since all code in
log() gets called every time a log event is triggered,
you may wish to set up a connection to your logging infrastructure in advance,
immediately before the first time you need to log the data.
To do this, you can override the
SimpleExperiment configure_logger() actually sets a class variable, once
per experiment name, so that a connection to the logging module is only made
once per interpreter session.
By default, each instance of an Experiment class will log auto-exposure once
per instance. But this can still result in a lot of writing when there are
many instances created for a particular unit’s assignment (for example,
if an experiment parameter is retrieved each time a person loads the home
So you may want to add some caching (e.g., with memcache) to prevent
unnecessary logging. This can be done by overriding the
Additional documentation for the
Experiment class and
can be found in the source code.