Sha256: f9a693c0fe69d1f3b616bcc5172f946ed415a1a2ba8e2fd6733789d45b40d023
Contents?: true
Size: 1.02 KB
Versions: 39
Compression:
Stored size: 1.02 KB
Contents
require 'date' module RFC5424 class Formatter Format = "<%d>1 %s %s %s %s %s %s %s" class << self def format( priority: 14, timestamp: nil, log: "", hostname: "-", app_name: "-", proc_id: "-", msg_id: "-", sd: "-" ) Format % [priority, format_time(timestamp), hostname[0..254], app_name[0..47], proc_id[0..127], msg_id[0..31], sd, log] end def format_time(timestamp) return "-" if timestamp.nil? return Time.at(timestamp.to_r).utc.to_datetime.rfc3339(6) if timestamp.is_a?(Fluent::EventTime) DateTime.strptime(timestamp.to_s, '%s').rfc3339(6) end end end class StructuredData attr_reader :sd_id, :sd_elements def initialize(sd_id:, sd_elements: {}) @sd_id = sd_id @sd_elements = sd_elements end def to_s el = @sd_elements.inject("") do |elements, tuple| elements + %{ #{tuple.first}="#{tuple.last}"} end %{[#{sd_id}#{el}]} end end end
Version data entries
39 entries across 39 versions & 1 rubygems