Spanish Total.js
English
Documentation For AI agents
Contents

Total.js audit logs

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

.md GitHub
On this page

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 for the app and copy its address with Copy URL address.

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

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

3. Create the file definitions/logger.js:

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):

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:

FieldValue
AppDemo project
Typeinfo
SchemaOrders.create
MessageOrder created: Demo product
data{"params":{},"query":{},"model":{"product":"Demo product","quantity":2}}

data holds the arguments and the model of the action.

Made in Europe