🪵 Logs
Overview
The TGG Banking system automatically logs all important banking activities to your database. These logs can be used for auditing, debugging, and tracking player actions. The logging system is built-in and requires no additional configuration - logs are automatically created when banking operations occur.
Features
- Automatic Logging: All banking operations are automatically logged
- Database Storage: Logs are stored in the
tgg_banking_logsdatabase table - Event Integration: Logs trigger server events for external integrations
- Discord Webhook Support: Built-in Discord webhook integration via custom file
- Comprehensive Coverage: Tracks accounts, cards, transactions, and loans
- Player Tracking: All logs include player identifiers and IBANs
- Batch Processing: Logs are queued and sent in batches for efficiency
Configuration
Discord Webhook Setup
The banking system includes a built-in Discord webhook integration. To enable it:
-
Create a Discord Webhook:
- Go to your Discord server settings
- Navigate to Integrations → Webhooks
- Create a new webhook and copy the webhook URL
-
Add the Convar to
server.cfg:Codeset bankingLogs "YOUR_DISCORD_WEBHOOK_URL_HERE" -
Restart the Resource:
bashrestart tgg-banking
Custom Logs Configuration
The logging system uses server/custom/logs.lua for Discord webhook integration. You can customize this file:
Excluding Log Types
To prevent certain log types from being sent to Discord, edit server/custom/logs.lua:
lualocal excludedLogTypes = { 'account_member_modified', -- Exclude member permission changes 'account_name_updated', -- Exclude account name updates 'card_limits_updated', -- Exclude card limit updates 'card_name_updated', -- Exclude card name updates }
Adjusting Batch Timeout
By default, logs are sent every 10 seconds if the queue hasn't reached 10 logs. To change this:
lualocal logsTimeout = 10 -- Time in seconds before queued logs are sent
Batch Size
Logs are automatically sent when 10 logs are queued for the same IBAN. This is hardcoded in the file but can be modified:
luaif #logQueue[iban] >= 10 then -- Change 10 to your desired batch size -- Send logs... end
Log Types
The banking system uses predefined log types. Here are all available log types:
Account Operations
| Log Type | Description |
|---|---|
account_created | Account was created |
account_name_updated | Account name was changed |
account_freeze | Account was frozen |
account_freeze_failed | Account freeze attempt failed |
account_unfreeze | Account was unfrozen |
account_unfreeze_failed | Account unfreeze attempt failed |
account_terminate | Account was terminated |
account_terminate_failed | Account termination attempt failed |
account_transfer_ownership | Account ownership was transferred |
account_transfer_ownership_failed | Account ownership transfer failed |
Account Members
| Log Type | Description |
|---|---|
account_member_added | Member was added to an account |
account_member_removed | Member was removed from an account |
account_member_modified | Member permissions were modified |
Transactions
| Log Type | Description |
|---|---|
deposit | Money was deposited to an account |
withdraw | Money was withdrawn from an account |
transfer | Money was transferred between accounts |
Card Operations
| Log Type | Description |
|---|---|
card_created | A new card was created |
card_item_given | Card item was given to player |
card_frozen | Card was frozen |
card_unfrozen | Card was unfrozen |
card_terminated | Card was terminated |
card_name_updated | Card name was updated |
card_limits_updated | Card limits were updated |
pin_changed_successfully | PIN was successfully changed |
pin_change_failed | PIN change attempt failed |
card_frozen_due_to_too_many_attempts | Card was frozen due to too many failed PIN attempts |
Loan Operations
| Log Type | Description |
|---|---|
loan | Loan was created |
loan_application | Loan application was submitted |
loan_approved | Loan was approved |
loan_rejected | Loan was rejected |
loan_created | Loan was created and approved |
loan_payment | Loan payment was made |
loan_payoff | Loan was paid off |
loan_overdue | Loan payment became overdue |
Savings Accounts
| Log Type | Description |
|---|---|
interest_earned | Interest was earned on a savings account |
early_withdrawal_penalty | Early withdrawal penalty was applied to a savings account |
Custom Logs
| Log Type | Description |
|---|---|
custom | Custom log type for special cases |
Server Event Integration
When a log is created, the system automatically triggers a server event that can be used for external integrations (Discord webhooks, logging systems, etc.):
luaTriggerEvent('banking:server:logs:create', iban, playerId, logType, logMessage)
Event Parameters
iban(string): The IBAN of the account related to the logplayerId(string): The identifier of the player who performed the actionlogType(string): The type of log (from LogType enum)logMessage(string): A descriptive message about what happened
Custom Event Handler
If you want to create your own logging system instead of using the built-in server/custom/logs.lua, you can listen to the event:
luaAddEventHandler('banking:server:logs:create', function(iban, playerId, logType, logMessage) -- Your custom logging logic here -- Example: Send to custom webhook or logging service local webhook = GetConvar('your_custom_webhook', '') if webhook ~= '' then PerformHttpRequest(webhook, function(err, text, headers) end, 'POST', json.encode({ embeds = {{ title = 'Banking Log', description = logMessage, fields = { {name = 'IBAN', value = iban, inline = true}, {name = 'Player', value = playerId, inline = true}, {name = 'Type', value = logType, inline = true} }, color = 3447003, timestamp = os.date('!%Y-%m-%dT%H:%M:%SZ') }} }), {['Content-Type'] = 'application/json'}) end end)