Handles all access logging functionality for the TAC system. Logs access events, card creation, and other security-related activities.
View on GitHub →-- In your extension:
function MyExtension.init(tac)
-- Log an access event
tac.logger.logAccess({
cardId = "tenant_1_player1",
cardName = "Player One",
doorId = "main_entrance",
doorName = "Main Entrance",
granted = true,
reason = "Valid card"
})
-- Get all logs
local logs = tac.logger.getAllLogs()
for _, log in ipairs(logs) do
print(log.cardName .. " accessed " .. log.doorName)
end
-- Get statistics
local stats = tac.logger.getStats()
print("Total accesses: " .. stats.totalAccesses)
print("Granted: " .. stats.granted)
print("Denied: " .. stats.denied)
end
AccessLogger.new(persistBackend)Initialize the logger with a persistent storage backend Creates a new logger instance that stores logs in persistent storage. The logger provides methods for recording access events and retrieving statistics.
persistBackend (function): The persist function for creating storage backendslogger.logAccess(eventType, options)Log an access event Records an access event with details about the card, door, and outcome. Events are stored with timestamps and can be retrieved for auditing. - message (string): Human-readable message - card (table): Card info with id, name, tags - door (table): Door info with name, tags - matched_tag (string): Tag that granted access - reason (string): Reason for denial or other outcome
eventType (string): Type of event: "access_granted", "access_denied", "card_created", "card_creation_cancelled"options (table): Event details with fields:logger.getAllLogs()Get all access logs Returns all logged events ordered chronologically.
logger.clearLogs()Clear all access logs Permanently deletes all logged events. Use with caution.
logger.getStats()Get access log statistics Returns statistics about logged events including totals for each event type. - total (number): Total number of events - access_granted (number): Count of successful accesses - access_denied (number): Count of denied accesses - card_created (number): Count of created cards - card_creation_cancelled (number): Count of cancelled card creations
logger.formatTimestamp(timestamp)Format timestamp for display
timestamp (number): - Unix timestamp in milliseconds