Logarithm::AbstractLogSource
Abstract base class for log data sources.
Log sources are responsible for ingesting log data from various sources (files, systemd journal, network streams, etc.) and feeding them into the anomaly detection pipeline via channels.
Interface
All log sources must implement three methods:
start(channel): Begin reading logs and send them to the channelstop: Stop reading and clean up resourcesdescriptions: Return human-readable source descriptions
Threading Model
Log sources typically run in background fibers/spawns to avoid blocking
the main pipeline. They should handle graceful shutdown via the stop method.
Example Implementation
class MyLogSource < AbstractLogSource
def start(channel : Channel(String))
@running = true
spawn do
while @running
log_line = read_next_log
channel.send(log_line)
end
channel.close
end
end
def stop
@running = false
end
def descriptions : Array(String)
["my custom log source"]
end
end
Built-in Implementations
JournaldLogSource: Reads from systemd journalVarlogLogSource: Reads from syslog filesMultiLogSource: Combines multiple sources
Instance methods
Returns human-readable descriptions of this log source.
Used for logging, auditing, and user interface purposes. Should return an array of strings describing the source(s).
Returns: Array of descriptive strings (e.g., ["systemd journal", "/var/log/syslog"])
Starts the log source and begins sending log lines to the channel.
This method should initiate log reading in a non-blocking manner, typically by spawning a background fiber. Log lines should be sent to the provided channel as strings.
Parameters:
- channel: Channel to send log lines to
The channel should be closed when log reading is complete or stopped.
Stops the log source and cleans up resources.
This method should signal background fibers to stop and close any open file handles, network connections, or system resources. After calling stop, the source should be ready to start again.