Journalctl
A wrapper for journalctl
Constants
Setup a logger for this class
Class methods
Builds the journalctl command array based on the provided filters. This is a private helper method.
Retrieves log entries surrounding a specific entry identified by a cursor.
Args: cursor: The journalctl cursor string for the central entry. count: The number of entries to retrieve before and after the central entry.
Returns: An Array(LogEntry) containing the 'before' entries, the target entry, and the 'after' entries, all in chronological order. Returns nil if the target cursor is not found or count is non-positive.
Retrieves a single log entry by its cursor.
Args: cursor: The journalctl cursor string.
Returns: A LogEntry object if found, or nil otherwise.
Retrieves a list of all known systemd service units using systemctl.
Returns: An Array(String) containing unique service unit names, sorted, or nil if an error occurs.
Queries the logs based on the provided criteria.
Args:
- since: A time offset, like -15m or nil for no filter
- unit: The systemd unit to filter by (e.g., "nginx.service").
- tag: The syslog identifier (tag) to filter by.
- live: A boolean indicating if the logs should be streamed live (not implemented yet).
- query: A string to filter logs by a specific search term. If it's in the form of a
journalctlfield=value pair, it will be used as a direct match filter, otherwise will be passed with-g. - priority: A string representing the log priority (0-7, e.g., "3" for errors).
- hostname: A string to filter logs by a specific hostname.
- sort_by: A string indicating the field to sort by (e.g., "timestamp", "priority", "message", "unit").
- sort_order: A string indicating the sort order, either "asc" for ascending or "desc" for descending.
Returns: An array of LogEntry