(since 1.3.0)

Audit logs

It might be useful to collect the history of all the fakes generated by your factories. FakerMaker allows you to stream (or write to a file) all the instances it builds for you. This is optional and disabled by default.

Enable logging

By default audit logging is disabled. The default output stream is STDOUT. The output target can either be an object that responds to puts, or be a string which will be interpreted as a file location to use to write to. If file path string is used, it will be opened in ‘append’ mode.

FakerMaker.configure do |config|
  config.audit = true
  config.audit_destination = '/tmp/faker_maker_audit_logs'
end

Audit streams

Immediately after each object is built and after the post-build hooks have completed, the instance details will be logged in line-delimited JSON (JSONL), to the stream or file. Each line is contained in an envelope containing the following metadata:

  • The timestamp at the time of logging
  • The name of factory
  • The class name of the object the factory instantiated

For example, given the factory:

FakerMaker.factory :user do 
  name {'Patsy Stone'}
  email {'patsy@fabulous.co.uk'}
  admin {false}
end

The audit log, on build, would look like:

{"timestamp":"2023-05-15T15:46:30+01:00","factory":"user","class":"User","body":{"name":"Patsy Stone","email":"patsy@fabulous.co.uk","admin":false}}

Copyright © 2019-2020 Nigel Brookes-Thomas. Distributed by an MIT license.