> For the complete documentation index, see [llms.txt](https://docs.fivemstats.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fivemstats.net/tgiann-fivem-stats-script/for-developers/log-api.md).

# Log API

Write logs from your own scripts and read them on the Server logs page.

Your scripts write log lines with one export. Lines are collected and sent in batches (every second, or every 500 lines), so a log call never waits. They are stored on your own server and shown on the [Server logs](https://docs.fivemstats.net/panel/server-logs.md) page.

## Write a line

```lua
exports["tgiann-fivem-stats-script"]:Log("bank", "info", "Transfer of $5000", {
    playerSource = source,
    targetSource = targetId,
    amount = 5000,
})

exports["tgiann-fivem-stats-script"]:Warn("anticheat", "Teleport detected", { playerSource = source })
```

| Part     | What to put there                                                                                                                    |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| Dataset  | A group of lines, like `bank` or `anticheat`. Letters, digits, `_`, `-` and `.`. Pick it with **Dataset** on the Server logs page    |
| Level    | `debug`, `info`, `warn` or `error`                                                                                                   |
| Message  | The line itself, up to 16 KB                                                                                                         |
| Metadata | A table, up to 32 KB. `playerSource` and `targetSource` add the players' identifiers and character, so the page can filter by player |

The resource that called the export is stored with the line. All exports with their parameters: [Exports](https://docs.fivemstats.net/tgiann-fivem-stats-script/for-developers/exports.md#logs).

## Levels

Lines below **Lowest level kept** are dropped before they are sent, from every script. It is `info` by default, so `debug` lines are dropped until you lower it. Turn on **Print to the server console** to also see each line in the FXServer console. Both are in [Settings > Logs](https://docs.fivemstats.net/panel/settings.md#logs).

## Automatic logs

The script logs these events on its own. Turn each one on or off and choose its dataset in [Settings > Logs](https://docs.fivemstats.net/panel/settings.md#logs).

| Event                                                         | On by default | Dataset       |
| ------------------------------------------------------------- | ------------- | ------------- |
| Player joins and leaves                                       | Yes           | `connections` |
| Chat messages                                                 | No            | `chat`        |
| Resource starts and stops                                     | Yes           | `resources`   |
| txAdmin actions (kicks, warns, bans, announcements, restarts) | Yes           | `txadmin`     |

## Scripts written for fmsdk

`Log`, `Info`, `Warn`, `Error` and `LogMessage` keep fmsdk's names, so fmsdk logging calls work unchanged.
