class Fluent::Client::CLI
Public Class Methods
new(args = [], options = {}, config = {})
click to toggle source
Calls superclass method
# File lib/fluent/client/cli.rb, line 22 def initialize(args = [], options = {}, config = {}) super(args, options, config) @global_options = config[:shell].base.options @logger = Fluent::Logger::FluentLogger.new(nil, host: @global_options['host'], port: @global_options['port']) @core = Core.new end
Public Instance Methods
post(tag)
click to toggle source
# File lib/fluent/client/cli.rb, line 32 def post(tag) data = options['data'] if options['time_key'].nil? @logger.post(tag, data) else @logger.post_with_time(tag, options['data'], data[options['time_key']].to_time) end end
post_json(tag)
click to toggle source
# File lib/fluent/client/cli.rb, line 42 def post_json(tag) results = parse_json(STDIN.read) results.each do |result| @logger.post(tag, result) end end
post_parse_text(tag)
click to toggle source
# File lib/fluent/client/cli.rb, line 75 def post_parse_text(tag) results = @core.parse_text(options['format'], options['time_format'], options['keys']) results.each do |result| @logger.post(tag, result) end end
stdin(tag)
click to toggle source
# File lib/fluent/client/cli.rb, line 50 def stdin(tag) @logger.post(tag, message: STDIN.read) end
stdin_line(tag)
click to toggle source
# File lib/fluent/client/cli.rb, line 55 def stdin_line(tag) STDIN.read.lines.each do |line| @logger.post(tag, message: line) end end
validate_parse()
click to toggle source
# File lib/fluent/client/cli.rb, line 66 def validate_parse @core.parse_text(options['format'], options['time_format'], options['keys']) end
Private Instance Methods
parse_json(buffer)
click to toggle source
# File lib/fluent/client/cli.rb, line 84 def parse_json(buffer) begin data = Yajl.load(buffer) rescue => e data = [] buffer.lines.each do |line| data << Yajl.load(line) end end data.class == Array ? data : [data] end