# Audit Logging

## Overview

Audit logging in Servoy enables tracking and recording of key events related to database tables, including data changes (inserts, updates, deletes) and data access (selects). This information is stored in a designated log table, which can reside in the same or a separate database server.

By configuring audit logging, developers can:

* **Ensure Compliance**: Meet regulatory requirements like the HIPAA Security Rule by tracking data views and changes.
* **Monitor Data Changes**: Capture and analyze changes to the data for debugging, operational insights, or analytics.
* **Use Audit Log Data**: Build forms against the log table, allowing users to review historical data changes or access modified records.

The log table is a standard database table, and its structure provides detailed tracking, including timestamps, action types (e.g., insert, update, delete, view), affected tables and columns, and user identifiers. Developers can also configure client statistics logging to track user connections and disconnections, enhancing system monitoring.

{% hint style="warning" %}
Performance Note:\
Logging introduces a performance impact, especially for high-traffic solutions. Using a separate database for the log table can help mitigate this impact by optimizing for insert operations and enabling independent backup or archiving strategies.
{% endhint %}

## How Audit Logging Works

In Servoy, audit logging captures specific actions performed on database tables — such as inserts, updates, deletes, and even data views — and records them in a special log table. This allows developers or administrators to track how data changes over time and who made those changes.

The system logs these actions automatically **only when explicitly enabled**, and **only for users who have permissions configured for tracking**.

## Configuring Audit Logging

To enable and configure audit logging in Servoy, follow these steps:

* **Set up a Log Server**:
  * Go to the database server configuration page in Servoy Developer.
  * Select a database server to act as the log server, check the `Log Server` option and save the change

    <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-d6c44a68fae8a4b12e705f5f798edc5a9d77f103%2Faudit-log-server.jpg?alt=media" alt=""><figcaption><p>set the Log Server</p></figcaption></figure></div>
  * Click the `Create Log Table` button to generate a `log` table in the selected database server.

    <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-2c906c454d976d2e0828146481322f6225ba7a98%2Faudit-log-server-create-log-table.jpg?alt=media" alt=""><figcaption><p>Create Log Table</p></figcaption></figure></div>

{% hint style="info" %}

```
Note:\
Using a separate database server for the log table can improve performance and allow for optimized backup or archiving strategies.
```

{% endhint %}

* **Enable Table Tracking**:
  * Open the desired table in the table editor.
  * Navigate to the `Security` tab.
  * Under the selected permissions' table settings, enable:

    <div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-d5fc10c99976aa4c9901abc41d0bd5c8d01e5b2d%2Faudit-log-table-security2.jpg?alt=media" alt=""><figcaption><p>Enable Table Tracking</p></figcaption></figure></div>

    * `Tracking (Insert/Update/Delete)` to log changes such as adds, edits, or deletes.
    * `Tracking (Select)` to log data reads or views.
* **Log Configuration Recommendations**:
  * Use a separate database for the log table if performance is critical.
  * Optimize the log database for insert operations, as most audit logging involves adding new records.
  * Plan a strategy for backing up or archiving large log tables.

## Application of Permissions

Audit logging is governed by **table-level security settings**. For each permission type (e.g., administrators, staff, limited users), you can choose whether to track:

* **Data changes** (insert, update, delete)
* **Data views** (select)

These settings are configured in the **Security tab** of the table editor and apply per permission type. For example:

* Administrators might have tracking enabled for all actions.
* Other permissions types might only have changes tracked, or no tracking at all.

As a result, audit logging in Servoy is both **selective** and **permission-based** — it only logs activity when the developer has chosen to track it, and only for the specified permission types.

## Using Audit Log Data

The audit log data is stored in a table called `log`, which is a standard database table. Developers can build forms or scripts to interact with this data, making it accessible for reporting or troubleshooting.

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-1fdc9bcd054cc64aacd8eedb84b84d9da3827424%2Faudit-log-table.jpg?alt=media" alt=""><figcaption><p>Log Table</p></figcaption></figure></div>

Below are the columns in the log table and their descriptions:

<table><thead><tr><th width="162">Column</th><th>Description</th></tr></thead><tbody><tr><td><code>event_time</code></td><td>The timestamp of the event (insert, update, delete, or select).</td></tr><tr><td><code>log_id</code></td><td>A unique, auto-incrementing identifier for the log record.</td></tr><tr><td><code>log_action</code></td><td>The action type: 1=delete, 2=insert, 3=update, 4=view.</td></tr><tr><td><code>server_name</code></td><td>The name of the database server where the action occurred.</td></tr><tr><td><code>table_name</code></td><td>The name of the affected table.</td></tr><tr><td><code>column_name</code></td><td>The name of the affected column (if applicable).</td></tr><tr><td><code>pk_data</code></td><td>The primary key data of the affected record.</td></tr><tr><td><code>old_data</code></td><td>The value of the data before the change (null for views).</td></tr><tr><td><code>new_data</code></td><td>The value of the data after the change or the viewed data.</td></tr><tr><td><code>user_uid</code></td><td>The unique identifier of the user who performed the action.</td></tr></tbody></table>

{% hint style="info" %}
Tip:\
This table can be used to access and restore any changed record in the database.
{% endhint %}

## Logging Client Statistics

Servoy also logs client connections and disconnections in a table called `client_stats`.

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-3e592695a803519cc7be31e299398c5d0057ff1f%2Faudit-client-stats-table.jpg?alt=media" alt=""><figcaption><p>Client Statistics Table</p></figcaption></figure></div>

This table can be created by clicking the `Create Client Statistics Table` button in the log server editor.

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-15b1d0045433aaa1d0700fd8e397e622cf5963c9%2Faudit-log-server-create-clientstats-table.jpg?alt=media" alt=""><figcaption><p>Create Client Statistics Table</p></figcaption></figure></div>

By default, this feature is enabled and tracks the following information:

<table><thead><tr><th width="204">Column</th><th>Description</th></tr></thead><tbody><tr><td><code>pk_id</code></td><td>A unique identifier for the log entry.</td></tr><tr><td><code>server_ip</code></td><td>The IP address of the Servoy Application Server.</td></tr><tr><td><code>server_name</code></td><td>The hostname of the server.</td></tr><tr><td><code>total_clients_running</code></td><td>The number of active clients at the time of the log entry.</td></tr><tr><td><code>client_id</code></td><td>A unique identifier for the client.</td></tr><tr><td><code>start_time</code></td><td>The timestamp when the client connected.</td></tr><tr><td><code>stop_time</code></td><td>The timestamp when the client disconnected.</td></tr><tr><td><code>extra_info</code></td><td>A column used to detect alterations to the logging data.</td></tr><tr><td><code>user_uid</code></td><td>The unique identifier of the logged-in user.</td></tr></tbody></table>

### Managing Client Statistics Logging

#### **Enable/Disable**

This logging is enabled by default but can be disabled in the admin page under "Admin Settings":

<div align="left"><figure><img src="https://3933488479-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjpWd52BKwABWxF2lScUK%2Fuploads%2Fgit-blob-5221113f321128bfed7fb2474f3e9b5bae84e999%2Faudit-log-admin-settings.jpg?alt=media" alt=""><figcaption><p>Enable/Disable Client Statistics Logging</p></figcaption></figure></div>
