tac.core.logger v1.0.1

Handles all access logging functionality for the TAC system. Logs access events, card creation, and other security-related activities.

Author: Twijn
View on GitHub →

Examples

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

Functions

MyExtension.init()

View source

In your extension:

AccessLogger.new(persistBackend)

View source

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.

Parameters:
Returns: table Logger instance with logAccess(), getAllLogs(), clearLogs(), getStats() methods

logger.logAccess(eventType, options)

View source

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

Parameters:

logger.getAllLogs()

View source

Get all access logs Returns all logged events ordered chronologically.

Returns: table Array of log entry objects with timestamp, type, message, card, door, etc.

logger.clearLogs()

View source

Clear all access logs Permanently deletes all logged events. Use with caution.

logger.getStats()

View source

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

Returns: table Statistics object with fields:

logger.formatTimestamp(timestamp)

View source

Format timestamp for display

Parameters:
Returns: string - formatted time