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

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

The question should be specific, self-contained, and written in natural language.
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.
