Module: Systemd::Journal::Writable::ClassMethods
- Defined in:
- lib/systemd/journal/writable.rb
Overview
methods in this module will be available as class methods on
{Systemd::Journal}
Instance Method Summary collapse
-
#log_stream(identifier, priority, opts = {}) ⇒ IO
Creates a new IO stream which writes newline-seperated messages to the journal.
-
#message(contents) ⇒ Object
write an event to the systemd journal.
-
#perror(message) ⇒ Object
write the value of the c errno constant to the systemd journal in the style of the perror() function.
-
#print(level, message) ⇒ Object
write a simple message to the systemd journal.
Instance Method Details
#log_stream(identifier, priority, opts = {}) ⇒ IO
Creates a new IO stream which writes newline-seperated messages to the journal.
45 46 47 48 49 50 51 52 53 54 |
# 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 |
#message(contents) ⇒ Object
write an event to the systemd journal.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/systemd/journal/writable.rb', line 75 def (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 |
#perror(message) ⇒ Object
write the value of the c errno constant to the systemd journal in the style of the perror() function.
59 60 61 62 |
# File 'lib/systemd/journal/writable.rb', line 59 def perror() rc = Native.sd_journal_perror() raise JournalError, rc if rc < 0 end |
#print(level, message) ⇒ Object
write a simple message to the systemd journal.
68 69 70 71 |
# File 'lib/systemd/journal/writable.rb', line 68 def print(level, ) rc = Native.sd_journal_print(level, .to_s.gsub('%', '%%')) raise JournalError, rc if rc < 0 end |