Sha256: 2f523cacfc9c1a146173ee0418d83c1e1dc72b2167bf5af62b2a1e0c48f23380

Contents?: true

Size: 755 Bytes

Versions: 2

Compression:

Stored size: 755 Bytes

Contents

#!/usr/bin/env ruby

# Purpose: to pretty print ALB log entries

require 'optparse'
require 'alblogs'
require 'json'
require 'csv'

options = {
  format: 'vertical'
}
OptionParser.new do |opts|
  opts.banner = "Usage: alblogpp [options]"

  opts.on("-f", "--format=FORMAT", "Output format vertical, json, csv, jsonl") do |v|
    options[:format] = v
  end
end.parse!

if options[:format] == 'csv'
  print Alblogs::Entry.fields.to_csv
end

Alblogs::Entry.each_entry($stdin) do |entry|
  case options[:format]
  when 'csv'
    print entry.to_a.to_csv
  when 'json'
    print JSON.pretty_generate(entry.to_h) + "\n"
  when 'jsonl'
    print entry.to_h.to_json + "\n"
  else
    entry.to_h.each do |key, value|
      puts "#{key}: #{value}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alblogs-0.1.8 bin/alblogpp
alblogs-0.1.7 bin/alblogpp