> For the complete documentation index, see [llms.txt](https://docs.redutzu.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redutzu.com/resources/redutzu-mdt/guides/logs.md).

# Logs

```lua
Config.UseLogs = true
```

{% code title="server/custom/functions/logs.lua" %}

````lua
local LOGS_WEBHOOK <const> = 'https://discord.com/api/webhooks/'
-- local WEBHOOKS <const> = {
--     ['incident'] = 'https://discord.com/api/webhooks/',
--     ...
-- }

local EMBED_SETTINGS <const> = {
    ['colors'] = {
        ['delete'] = 16720402,
        ['create'] = 515594,
        ['update'] = 16757025
    }
}

--- Sends the log to discord (you can change this)
---@param action string (create, update, delete)
---@param type string (incident, evidence, warrant, etc.)
---@param data object (example: { name: 'updated name', description: 'updated description' })
---@param source number | string (creator of the log)
function CreateLog(action, recordType, data, source)
    local fields = {}

    if type(data) == 'table' then
        for key, value in pairs(data) do
            local val = type(value) ~= 'string' and '```js\n' .. json.encode(value) .. '```' or value

            fields[#fields + 1] = {
                name = key,
                value = val,
                inline = true
            }
        end
    else
        fields[#fields + 1] = { name = 'id', value = tostring(data) }
    end

    PerformHttpRequest(
        LOGS_WEBHOOK, -- if you want to use a channel for all logs
        -- WEBHOOKS[recordType], -- if you want to use a different channel for each category
        function(err, text, headers)
            if err == 400 then
                error('Caught an error while sending the log to discord')
                return
            end
        end, 'POST',
        json.encode({
            embeds = {{
                ['color'] = EMBED_SETTINGS['colors'][action],
                ['title'] = ('New action (%s - %s)'):format(action, recordType),
                ['fields'] = fields,
                ['timestamp'] = os.date('!%Y-%m-%dT%H:%M:%S'),
                ['footer'] = {
                    ['text'] = 'Made with ♥ by Redutzu\'s Scripts'
                }
            }}
        }), {
            ['Content-Type'] = 'application/json'
        }
    )
end

````

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.redutzu.com/resources/redutzu-mdt/guides/logs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
