class

Journalctl

Inherits Reference < Object

A wrapper for journalctl

Constants

Log = ::Log.for(self)

Setup a logger for this class

Class methods

build_query_command(since : String | Nil = nil, unit : String | Nil = nil, tag : String | Nil = nil, query : String | Nil = nil, priority : String | Nil = nil, hostname : String | Nil = nil, lines : Int32 = 5000) : Array(String)

Builds the journalctl command array based on the provided filters. This is a private helper method.

Source
context(cursor : String, count : Int32) : Array(LogEntry) | Nil

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.

Source
get_entry_by_cursor(cursor : String) : LogEntry | Nil

Retrieves a single log entry by its cursor.

Args: cursor: The journalctl cursor string.

Returns: A LogEntry object if found, or nil otherwise.

Source
known_service_units

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.

Source
query(since : String | Nil = nil, unit : String | Nil = nil, tag : String | Nil = nil, query : String | Nil = nil, priority : String | Nil = nil, hostname : String | Nil = nil, lines : Int32 = 5000, sort_by : String | Nil = nil, sort_order : String | Nil = nil) : Array(LogEntry) | Nil

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 journalctl field=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

Source

Nested types