# log Action

Used to augment the [access log](https://sevenval.gitbook.io/flat/administration/logging#access-log) with [custom fields](https://sevenval.gitbook.io/flat/cookbook/custom-logging).

## Syntax

```markup
<log>
{
  "field1": "value1",
  "field2": "value2"
}
</log>
```

The action takes a JSON object as its argument. The object may contain nested fields. A [JSON template](https://sevenval.gitbook.io/flat/reference/templating) may be used for dynamic fields. (The [recipe](https://sevenval.gitbook.io/flat/cookbook/custom-logging) has plenty examples for that.)

## Usage

All name/value pairs of the object are registered for logging. When the system writes the `flat_access` event the registered fields are included in that log line.

[System log fields](https://sevenval.gitbook.io/flat/administration/logging#fields) like `timestamp` cannot be overriden.

You can call the action multiple times. Fields of the same name are overwritten. However, nested fields are merged into the previously registered log fields. The order of fields is maintained.

```markup
<log>
{
  "user": {
    "name": "alice"
  }
}
</log>
<log>
{
  "user": {
    "role": "admin"
  }
}
</log>
```

The merged custom log fields are:

```javascript
{
  "user": {
    "name": "alice",
    "role": "admin"
  }
}
```

They would appear in the [access log](https://sevenval.gitbook.io/flat/administration/logging#access-log) like this:

```javascript
{"timestamp": …,"user":{"name":"alice","role":"admin"}}
```

Fields with `null` values are not included in the log event. In order to remove a previously registered field, you can unset it with `null` value.

The `user` field of the previous example can be unregistered like this:

```markup
<log>
{
  "user": null
}
</log>
```

## See also

* [Logging](https://sevenval.gitbook.io/flat/administration/logging) (Administration)
* [Custom Logging](https://sevenval.gitbook.io/flat/cookbook/custom-logging) (Cookbook)
* [`get-log()` function](https://sevenval.gitbook.io/flat/reference/functions/get-log) (Reference)
