Skip to content
BasiX Media

Logs from Lua

Send structured events from a resource.

On this page

Send events from Lua

Install the basix resource (see Install the basix resource), then call the logging exports — log(level, message, options) or the shortcuts info, warn, error, debug (message, options). Options: player, resource (defaults to the calling resource), metadata. Events are buffered and sent every 2 seconds in one request, so logging never blocks a tick. Up to 400 events are kept in memory if the API cannot be reached.

Lua
exports.basix:warn('Suspicious money add', {
    player = GetPlayerIdentifierByType(source, 'license'),
    resource = 'esx_core',
    metadata = { amount = 999999, source = 'admin' },
})

exports.basix:info('Player bought a car', {
    player = GetPlayerIdentifierByType(source, 'license'),
    metadata = { model = 'sultan', price = 25000 },
})

exports.basix:log('error', 'Payment failed', { metadata = { reason = 'insufficient funds' } })
Event fieldTypeNotes
message (or body)stringRequired. Up to 8,000 characters. Events without one are skipped.
levelstringtrace, debug, info, warn, error, fatal. Anything else becomes info.
playerstringAny identifier, up to 120 characters. Builds player profiles.
resourcestringUp to 120 characters.
metadataobjectAny JSON, up to 8,000 bytes once serialized. Larger metadata is dropped.
timestampISO string or msOptional. Must be within the last 365 days and not more than 1 day ahead, otherwise the server time is used.

Limits: 500 events per request, 240 requests per minute per key. The resource batches for you; batch your own events too if you bypass it. A full quota answers 413 QUOTA_EXCEEDED.

Under the hood, and without the resource

exports.basix:warn (and friends) just batch your events and POST them to https://upload.basix.media/api/v1/logs as JSON — this is what runs when you don't have the resource installed, for example from a web backend running alongside your server.

PerformHttpRequest('https://upload.basix.media/api/v1/logs', function(status, body)
    if status ~= 200 then print('basix logs failed', status, body) end
end, 'POST', json.encode({
    dataset = 'admin',
    events = { { level = 'info', message = 'Ban issued', player = 'license:3f9a2b...', metadata = { by = 'admin1' } } },
}), {
    ['Content-Type'] = 'application/json',
    ['Authorization'] = 'Bearer ' .. GetConvar('basix_key', ''),
})

Response:

json
{ "accepted": 1, "used": { "bytes": "2097152" }, "quota": { "bytes": "10737418240" } }

Body: { "dataset": "...", "events": [ ... ] }, a bare array of events, or a single event. dataset can also be passed as ?dataset=. Default: default.

Try it on your own server

Create a free account and your API key is ready in about two minutes. 3 GB included, bandwidth never billed, no card needed.

Create a free account
Logs from Lua — FiveM docs — BasiX