Class: Fluent::Client::CLI
- Inherits:
-
Thor
- Object
- Thor
- Fluent::Client::CLI
- Defined in:
- lib/fluent/client/cli.rb
Instance Method Summary collapse
-
#initialize(args = [], options = {}, config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #post(tag) ⇒ Object
- #post_json(tag) ⇒ Object
- #post_parse_text(tag) ⇒ Object
- #stdin(tag) ⇒ Object
- #stdin_line(tag) ⇒ Object
- #validate_parse ⇒ Object
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 = [], = {}, config = {}) super(args, , config) @global_options = config[:shell].base. @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 = ['data'] if ['time_key'].nil? @logger.post(tag, data) else @logger.post_with_time(tag, ['data'], data[['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(['format'], ['time_format'], ['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_parse ⇒ Object
66 67 68 |
# File 'lib/fluent/client/cli.rb', line 66 def validate_parse @core.parse_text(['format'], ['time_format'], ['keys']) end |