class

Journalctl::LogEntry

Inherits JSON::Serializable < Reference < Object

Represents a single log entry retrieved from journalctl.

This class is used to parse and serialize log data. It includes JSON::Serializable to allow easy conversion to and from JSON.

Constructors

new(timestamp : Time, message_raw : String | Nil, raw_priority_val : String | Nil, internal_unit_name : String | Nil = nil, hostname : String | Nil = nil, data : Hash(String, String) = {} of String => String)

Constructor used by JSON::Serializable. It's called with named arguments matching property names, after converters are applied.

Source
new(*, __pull_for_json_serializable pull : JSON::PullParser)
Source

Class methods

from_json(string_or_io, root : String | Nil = nil)

Custom from_json class method to take control of parsing. This allows us to populate the 'data' field with all key-value pairs from the JSON, converting all values to strings.

Source

Instance methods

data

Will hold all raw data from journalctl as string key-value pairs

Source
data=(data : Hash(String, String))

Will hold all raw data from journalctl as string key-value pairs

Source
formatted_priority

Converts the numeric priority string to its textual representation.

Source
formatted_timestamp(format = "%b %d %H:%M:%S") : String

Converts the raw timestamp string to a formatted date/time string. Example format: "2023-10-27 15:04:05.123"

Source
formatted_timestamp_with_timezone(format = "%m-%d %H:%M:%S") : String

Converts the timestamp to a formatted string using the configured timezone

Source
hostname

Getter for the hostname

Source
hostname=(hostname : String | Nil)
Source
internal_unit_name
Source
internal_unit_name=(internal_unit_name : String | Nil)
Source
message

Getter for the cleaned message

Source
message_raw
Source
message_raw=(message_raw : String | Nil)
Source
priority

Getter for the priority string (e.g., "0" to "7") This maintains compatibility with previous direct priority field access.

Source
raw_priority_val
Source
raw_priority_val=(raw_priority_val : String | Nil)
Source
timestamp

The __REALTIME_TIMESTAMP from journalctl is microseconds since epoch, as a string.

Source
timestamp=(timestamp : Time)

The __REALTIME_TIMESTAMP from journalctl is microseconds since epoch, as a string.

Source
to_s

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.

Source
unit

Getter for the cleaned unit name

Source