The debug system in Pixel Logs provides advanced logging capabilities for development, troubleshooting, and monitoring. This guide explains how to use and configure the debug system.
Important
Debug logging requires the pixel_logs_debug convar to be set to true.
To enable the debug system, set the following convar in your pixel_convars.cfg:
set pixel_logs_debug "true"You can set a separate webhook for debug logs:
set pixel_logs_debug_webhook "YOUR_DEBUG_WEBHOOK_URL"If not set, debug logs will be sent to the main webhook.
Configure how many debug logs to keep in memory:
set pixel_logs_debug_maxlogs "100"-- Add a debug log with level, message, and optional data
exports['pixel_logs']:AddDebugLog(level, message, data)
-- Examples:
exports['pixel_logs']:AddDebugLog('info', 'Player joined the server', {
player = source,
name = GetPlayerName(source)
})
exports['pixel_logs']:AddDebugLog('warning', 'Low server performance', {
fps = GetConvarInt('sv_maxclients', 32),
players = #GetPlayers()
})
exports['pixel_logs']:AddDebugLog('error', 'Failed to process payment', {
error = 'Invalid amount',
player = source,
amount = 1000
})The following log levels are available:
info: General information (blue)warning: Warnings (yellow)error: Errors (red)debug: Debug information (gray)
-- Get a debug log by index (1-based)
local log = exports['pixel_logs']:GetDebugLog(1)-- Get all debug logs
local logs = exports['pixel_logs']:GetAllDebugLogs()-- Clear all debug logs
exports['pixel_logs']:ClearDebugLogs()Tip
The CatchError export is a powerful tool for catching and logging errors in your code.
The debug system includes a powerful error catching mechanism:
-- Catch and log errors in a function
exports['pixel_logs']:CatchError(function()
-- Your code here
local result = someFunction()
return result
end)
-- Catch and log errors with source and data
exports['pixel_logs']:CatchError('Failed to process payment', 'PaymentSystem', {
player = source,
amount = 1000
})Debug logs include the following information:
- Level: The log level (info, warning, error, debug)
- Message: The log message
- Timestamp: When the log was created
- Data: Additional data associated with the log
- Resource: The resource that created the log
- Stack Trace: For errors, a stack trace is included
-- Track function entry
exports['pixel_logs']:AddDebugLog('debug', 'Entering function: ProcessPayment', {
player = source,
amount = 1000
})
-- Your function code here
-- Track function exit
exports['pixel_logs']:AddDebugLog('debug', 'Exiting function: ProcessPayment', {
player = source,
result = 'success'
})-- Start timing
local startTime = os.clock()
-- Your code here
-- End timing and log
local endTime = os.clock()
local duration = endTime - startTime
exports['pixel_logs']:AddDebugLog('info', 'Operation completed', {
duration = string.format('%.4f seconds', duration),
operation = 'Database Query'
})-- Log state changes
local previousState = playerState
playerState = newState
exports['pixel_logs']:AddDebugLog('info', 'Player state changed', {
player = source,
previous = previousState,
current = playerState,
reason = reason
})Tip
When troubleshooting, enable debug mode and add strategic debug logs at key points in your code.
When troubleshooting, enable debug mode and add strategic debug logs:
-- Add debug logs at key points in your code
exports['pixel_logs']:AddDebugLog('debug', 'Processing payment request', {
player = source,
amount = 1000
})
-- After validation
exports['pixel_logs']:AddDebugLog('debug', 'Payment validation passed', {
player = source,
amount = 1000
})
-- Before database operation
exports['pixel_logs']:AddDebugLog('debug', 'Updating database', {
player = source,
amount = 1000
})
-- After database operation
exports['pixel_logs']:AddDebugLog('debug', 'Database updated successfully', {
player = source,
amount = 1000
})Use the CatchError export to catch and log errors:
exports['pixel_logs']:CatchError(function()
-- Your code here
local result = someFunction()
return result
end)-
Use Appropriate Log Levels
- Use
infofor general information - Use
warningfor potential issues - Use
errorfor actual errors - Use
debugfor detailed debugging information
- Use
-
Include Relevant Data
- Always include player IDs when relevant
- Include timestamps for time-sensitive operations
- Add context to make logs more useful
-
Don't Over-log
- Only log what's necessary
- Avoid logging sensitive information
- Don't log too frequently for high-volume events
-
Use Structured Data
- Use tables for complex data
- Use consistent field names
- Format data for readability
-
Regular Maintenance
- Clear debug logs periodically
- Review and adjust log retention settings
- Disable debug mode in production when not needed
- Troubleshooting Guide - Using debug logs to solve common issues
- Configuration Guide - Configure debug settings
- Events Guide - Debug exports and events