Sha256: 8573820e1df123e0e3e428c4254acf8d55e7cdd81758c6b3afd9b5d6d848b9d2

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

---
layout: default
title: Audit (History) Logs
parent: Usage
nav_order: 10
---

_(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.

```ruby
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:

```ruby
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}}
```

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
faker_maker-2.1.2 docs/usage/audit_logs.md
faker_maker-2.1.1 docs/usage/audit_logs.md
faker_maker-2.0.0 docs/usage/audit_logs.md
faker_maker-1.3.0 docs/usage/audit_logs.md