module Systemd::Journal::Writable::ClassMethods
methods in this module will be available as class methods on
{Systemd::Journal}
Public Instance Methods
Creates a new IO stream which writes newline-seperated messages to the journal. @param identifier [String] this value will be passed as
SYSLOG_IDENTIFIER to the journal.
@param priority [Integer] the log level for events writen to this
stream.
@param opts [Hash] @option opts [Boolean] :prefix true to enable kernel-style log
priority prefixes
@return [IO]
# File lib/systemd/journal/writable.rb, line 45 def log_stream(identifier, priority, opts = {}) fd = Native.sd_journal_stream_fd( identifier, priority, !opts[:prefix].nil? ) raise JournalError, fd if fd < 0 IO.new(fd, File::WRONLY, encoding: Encoding::UTF_8) end
write an event to the systemd journal. @param [Hash] contents the set of key-value pairs defining the event.
# File lib/systemd/journal/writable.rb, line 75 def message(contents) items = contents.flat_map do |k, v| value = v.to_s.gsub('%', '%%') [:string, "#{k.to_s.upcase}=#{value}"] end # add a null pointer to terminate the varargs items += [:string, nil] rc = Native.sd_journal_send(*items) raise JournalError, rc if rc < 0 end
write the value of the c errno constant to the systemd journal in the style of the perror() function. @param [String] message the text to prefix the error message with.
# File lib/systemd/journal/writable.rb, line 59 def perror(message) rc = Native.sd_journal_perror(message) raise JournalError, rc if rc < 0 end
write a simple message to the systemd journal. @param [Integer] level one of the LOG_* constants defining the
severity of the event.
@param [String] message the content of the message to write.
# File lib/systemd/journal/writable.rb, line 68 def print(level, message) rc = Native.sd_journal_print(level, message.to_s.gsub('%', '%%')) raise JournalError, rc if rc < 0 end