Class: Fluent::Client::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/fluent/client/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
26
27
# 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

Instance Method Details

#post(tag) ⇒ Object



32
33
34
35
36
37
38
39
# 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) ⇒ Object



42
43
44
45
46
47
# 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) ⇒ Object



75
76
77
78
79
80
# 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) ⇒ Object



50
51
52
# File 'lib/fluent/client/cli.rb', line 50

def stdin(tag)
  @logger.post(tag, message: STDIN.read)
end

#stdin_line(tag) ⇒ Object



55
56
57
58
59
# 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_parseObject



66
67
68
# File 'lib/fluent/client/cli.rb', line 66

def validate_parse
  @core.parse_text(options['format'], options['time_format'], options['keys'])
end