# Audit Logs

In our app we have audit log system to monitor changes that can influence user data by the time logs monitor any changes on businesses and leads (edit, create, delete, assign lead to business), also they monitor comments delete and comments update. With that system members of the team can easily monitor who performed specifyc actions. Every user can work with logs only in read only mode, there is no possibility to delete or update any of logs. Logs generating automatically when user perform actions. It is one table for all entity logs.

Now let's see what the `AuditLoggerEntity` consists of:

* **action** - Identifies which action the log recorded (e.g., business update, lead update). For each action, we use an enum `AuditLogActions` and simple integers to identify actions (for better database performance, as integers are faster than strings).\
  \&#xNAN;*Note:* Do not change these numbers if logs already exist, as this will cause incorrect display in the UI. To add a new action to monitor, add a new value at the end of the enum with the identifier number set to `max + 1`.
* **changedObjects** - A `jsonb` field that consists of three objects:
  * **previous** - The full entity object before a certain action.
  * **current** - The full entity object after the action is performed.
  * **difference** - Contains only the fields that were changed.
* **user** - A nullable relation to the `auth-users` table. On user deletion, this field is set to `null` to retain the log regardless.
* **userEmail** - A string field duplicating `user.email`, allowing tracking of who performed the action even if the user is deleted.
* **entityType** - Identifies the entity on which the action was performed (e.g., `LeadEntity` or `BusinessEntity`). This is also an integer field for performance. Other entities can be added to the `AuditLogEntityTypes` enum.
* **numberIdentifier** - Stores the ID of the record on which the action was performed.
* **isImpersonated** - A boolean field indicating if the action was performed during impersonation.
* **createdAt** - A timestamp to record when the action was performed (we don’t need an `updatedAt` field, as logs cannot be edited).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://intercode.gitbook.io/intercode-saas-kit/features/audit-logs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
