# logs

Configure Discord webhook logging in `editable/logs.lua`.

***

## Configuration

### Enable/Disable Logging

```lua
LogsConfig = {}

LogsConfig.Enabled = true  -- Master toggle for all logs
```

***

### Screenshot Webhook

Separate webhook for screenshot uploads:

```lua
LogsConfig.ScreenshotWebhook = 'https://discord.com/api/webhooks/...'
```

***

### Command Webhooks

Configure individual command logging:

{% code title="editable/logs.lua" %}

```lua
LogsConfig.Commands = {
    -- Ban System
    ban = { 
        enabled = true, 
        webhook = 'https://discord.com/api/webhooks/...', 
        color = 0xFF0000,  -- Red
        title = 'Player Banned' 
    },
    unban = { 
        enabled = true, 
        webhook = '', 
        color = 0x00FF00,  -- Green
        title = 'Player Unbanned' 
    },
    bans = { 
        enabled = true, 
        webhook = '', 
        color = 0x7289DA,  -- Discord Blue
        title = 'Ban List' 
    },
    
    -- Warning System
    warn = { enabled = true, webhook = '', color = 0xFFFF00, title = 'Player Warned' },
    unwarn = { enabled = true, webhook = '', color = 0x00FF00, title = 'Warning Removed' },
    clearwarns = { enabled = true, webhook = '', color = 0x00FF00, title = 'Warnings Cleared' },
    warnings = { enabled = true, webhook = '', color = 0xFFFF00, title = 'Warnings List' },
    
    -- Player Management
    kick = { enabled = true, webhook = '', color = 0xFFA500, title = 'Player Kicked' },
    players = { enabled = true, webhook = '', color = 0x7289DA, title = 'Player List' },
    player = { enabled = true, webhook = '', color = 0x3498DB, title = 'Player Info' },
    
    -- Health & Status
    heal = { enabled = true, webhook = '', color = 0x2ECC71, title = 'Player Healed' },
    revive = { enabled = true, webhook = '', color = 0x2ECC71, title = 'Player Revived' },
    freeze = { enabled = true, webhook = '', color = 0x3498DB, title = 'Player Frozen' },
    unfreeze = { enabled = true, webhook = '', color = 0x3498DB, title = 'Player Unfrozen' },
    crashplayer = { enabled = true, webhook = '', color = 0xFF0000, title = 'Player Crashed' },
    
    -- Economy
    givemoney = { enabled = true, webhook = '', color = 0xFFD700, title = 'Money Given' },
    giveitem = { enabled = true, webhook = '', color = 0x9B59B6, title = 'Item Given' },
    givecar = { enabled = true, webhook = '', color = 0xE67E22, title = 'Vehicle Spawned' },
    
    -- Jobs & Permissions
    setjob = { enabled = true, webhook = '', color = 0x3498DB, title = 'Job Changed' },
    setgroup = { enabled = true, webhook = '', color = 0xE74C3C, title = 'Group Changed' },
    
    -- Teleport
    bring = { enabled = true, webhook = '', color = 0x9B59B6, title = 'Player Brought' },
    teleport = { enabled = true, webhook = '', color = 0x9B59B6, title = 'Player Teleported' },
    
    -- Utilities
    announce = { enabled = true, webhook = '', color = 0xFFD700, title = 'Announcement' },
    blackout = { enabled = true, webhook = '', color = 0x2C3E50, title = 'Blackout Toggled' },
    ss = { enabled = true, webhook = '', color = 0x3498DB, title = 'Screenshot Requested' },
    ping = { enabled = true, webhook = '', color = 0x7289DA, title = 'Ping' },
    serverinfo = { enabled = true, webhook = '', color = 0x7289DA, title = 'Server Info' },
    
    -- Server Control
    restartserver = { enabled = true, webhook = '', color = 0xFF0000, title = 'Server Restart' },
    stopserver = { enabled = true, webhook = '', color = 0xFF0000, title = 'Server Stop' },
    kickall = { enabled = true, webhook = '', color = 0xFFA500, title = 'All Players Kicked' },
    txannounce = { enabled = true, webhook = '', color = 0xFFD700, title = 'txAdmin Announcement' },
}
```

{% endcode %}

***

## Color Reference

| Color     | Hex     | Decimal  | Usage                      |
| --------- | ------- | -------- | -------------------------- |
| 🔴 Red    | #FF0000 | 0xFF0000 | Bans, crashes, server stop |
| 🟢 Green  | #00FF00 | 0x00FF00 | Unbans, positive actions   |
| 🟡 Yellow | #FFFF00 | 0xFFFF00 | Warnings                   |
| 🟠 Orange | #FFA500 | 0xFFA500 | Kicks                      |
| 🔵 Blue   | #3498DB | 0x3498DB | Info, freeze               |
| 🟣 Purple | #9B59B6 | 0x9B59B6 | Teleport, items            |
| 🟤 Gold   | #FFD700 | 0xFFD700 | Money, announcements       |
| ⚫ Discord | #7289DA | 0x7289DA | Lists, general             |

***

## Log Format

Each log includes:

| Field   | Description                     |
| ------- | ------------------------------- |
| Command | Command used (e.g., `!ban`)     |
| Admin   | Discord user who executed       |
| Time    | Timestamp (YYYY-MM-DD HH:MM:SS) |
| Result  | Command result/details          |

***

## Example Log Embed

{% code title="example-log.json" %}

```json
{
    "title": "Player Banned",
    "color": 16711680,
    "fields": [
        { "name": "Command", "value": "!ban", "inline": true },
        { "name": "Admin", "value": "Admin#1234", "inline": true },
        { "name": "Time", "value": "2025-12-30 15:30:00", "inline": true },
        { "name": "Result", "value": "Banned Player (ID: 1) for 7d\nBan ID: ABC12345\nReason: Cheating" }
    ],
    "footer": { "text": "SL-Bot Logs" }
}
```

{% endcode %}

***

## Webhook Tips

{% hint style="info" %}
Use separate webhooks and channels to keep logs organized, and disable specific logs you don't need.
{% endhint %}

### Separate Webhooks

Use different webhooks for different log types:

```lua
-- Create separate channels in Discord:
-- #ban-logs
-- #warn-logs  
-- #admin-logs

LogsConfig.Commands = {
    ban = { webhook = 'https://discord.com/api/webhooks/.../ban-webhook' },
    warn = { webhook = 'https://discord.com/api/webhooks/.../warn-webhook' },
    kick = { webhook = 'https://discord.com/api/webhooks/.../admin-webhook' },
}
```

### Disable Specific Logs

```lua
LogsConfig.Commands = {
    ping = { enabled = false, webhook = '' },  -- Don't log !ping
    players = { enabled = false, webhook = '' },  -- Don't log !players
}
```

***

## Using SendLog in Custom Commands

Use the `SendLog` function in your custom commands:

{% code title="custom-command.lua" %}

```lua
CustomCommands.mycommand = function(args, admin)
    -- Do something...
    
    SendLog('mycommand', admin, 'Action completed successfully')
    
    return { success = true, message = 'Done!' }
end
```

{% endcode %}

Don't forget to add the command to `LogsConfig.Commands`:

```lua
LogsConfig.Commands = {
    mycommand = { enabled = true, webhook = '', color = 0x3498DB, title = 'My Command' },
}
```
