TailTales now supports a callback system that allows you to process each new record as it's added. This system is implemented through the record_processors array in Lua.
- Initialization: The
record_processorsarray is initialized in_init.lua - Processing: When a new record is added, all callbacks in the array are executed
- Input: Each callback receives the current record (with builtin attributes already set)
- Output: Each callback returns a table with new attributes to add/update/remove
- Removal: Use
nilvalues to remove attributes
-- Add a processor function to the record_processors array
table.insert(record_processors, function(record)
-- Your processing logic here
return {
new_attribute = "value",
another_attribute = "another_value"
}
end)-- Add a processor that calculates the byte count of each line
table.insert(record_processors, function(record)
local bytes_count = #record.original
return {
bytes_count = tostring(bytes_count)
}
end)-- Remove unwanted attributes
table.insert(record_processors, function(record)
return {
unwanted_field = nil -- This removes the attribute
}
end)The record passed to processors contains:
original: The raw log lineword_count: Number of words (automatically added)filename: Source filename (if available)line_number: Line number in the file- Any other attributes extracted by builtin extractors
The callback system is integrated at the following points:
- New Records: When new records are added via
TuiEvent::NewRecord - File Processing: During parallel file reading
- Stream Processing: When reading from stdin or command output
- If a processor function fails, an error message is printed but processing continues
- The system is designed to be robust and not break the main application flow
- Processors are executed synchronously for each record
- Keep processor functions lightweight for best performance
- Complex processing should be done in background threads if needed
You can test the callback system using the provided example scripts:
# Load the bytes count processor and process a log file
./tt --lua examples/bytes_count_processor.lua your_log_file.logThe processor will automatically add a bytes_count attribute to each record showing the size of the original line in bytes.
The --lua flag allows you to execute a Lua script before processing log files:
# Execute a script and then process files normally
./tt --lua my_processors.lua access.log error.log
# Execute script and read from stdin
./tt --lua my_processors.lua -
# Execute script and run a command
./tt --lua my_processors.lua -- tail -f /var/log/app.logThe script executes in normal mode (not REPL mode), so you stay in the main view to see the processed records.