---
title: Total.js audit logs
project: OpenLogger
version: 1.0
section: recipes
language: en
license: MIT
url: https://totaljs.es/docs/openlogger/1-0/recipes/totaljs-audit/
updated: 2026-11-19T08:02:31.630Z
---

# Total.js audit logs

> Send the audit logs of a Total.js 4 app to OpenLogger with $.audit().

A Total.js 4 app writes audit logs with `$.audit()`. With one definition file, these logs go to OpenLogger instead of a local file.

## Set it up

**1.** In OpenLogger, create an [API token](../../guides/api-tokens/) for the app and copy its address with **Copy URL address**.

**2.** Add the address to the `config` file of your Total.js app:

```text
name       : Demo project
openlogger : https://logs.example.com/?token=YOUR_TOKEN
```

**3.** Create the file `definitions/logger.js`:

```javascript
DEF.onAudit = function(name, data) {
	data.app = CONF.name;
	data.sessionid = data.thread = undefined;
	RESTBuilder.POST(CONF.openlogger, data).keepalive().callback(ERROR('OpenLogger'));
};
```

The app name in OpenLogger is the `name` from the config file.

## Write audit logs

Call `$.audit()` in a schema action, with a message and, optionally, a type (`info`, `warning`, `error` or `success`):

```javascript
NEWSCHEMA('Orders', function(schema) {

	schema.define('product', String, true);
	schema.define('quantity', Number);

	schema.action('create', {
		name: 'Create an order',
		action: function($, model) {
			// ... save the order ...
			$.audit('Order created: ' + model.product);
			$.success();
		}
	});

});
```

## What arrives in OpenLogger

Running this action with the product `Demo product` stores this log:

| Field | Value |
|---|---|
| **App** | `Demo project` |
| **Type** | `info` |
| **Schema** | `Orders.create` |
| **Message** | `Order created: Demo product` |
| `data` | `{"params":{},"query":{},"model":{"product":"Demo product","quantity":2}}` |

`data` holds the arguments and the model of the action.
