fluent-format 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60872a23fdf2060c3e94c301c8b6f5e1e3eb3a66
4
- data.tar.gz: 155f128a5bd00841a294aa2beeb4b3f6718d96ca
3
+ metadata.gz: 495a2bd0d34f9a30ff0ac8be3700d5e361cf6150
4
+ data.tar.gz: 01554a964c734cedf4f7c2cfb0e915e3c608a158
5
5
  SHA512:
6
- metadata.gz: d852f71daed2299560ba8b8bbbdce60eb2ec6d09d27d15fcc455390b79cbf6bc89fb422dc418169e0778ec21a1d6219c4a05f083340fdf610bb813d751230258
7
- data.tar.gz: f0c342aebc5a321dd7e59196200a91b5b0a19cee46d4cadb551c91ce01f8f99fdde936b0480e46e17e3c1fc40b49ea2abf0c950090f5601ed22f8fd95a925261
6
+ metadata.gz: 2e5e950a92c5fb60dd20e86cebe99946c0b6410f1e7c20a55100a54fa0ac6923237b67bccd155d6859e48e59d0a5f9e5f2ef350da16325f2fa28bb3d467e27e1
7
+ data.tar.gz: 36673c63cfd92f6e12c3aebc294b64132e37bed1c59780266066ea529ff29f827e75e7c2e122a7e5be3e828c997a9f8a6fef16cc6119d51ad1e7e58d1f35488a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.2 (2014/02/08)
2
+
3
+ Enhancement:
4
+
5
+ * Define specifications of STDERR output
6
+
1
7
  ## 0.2.1 (2014/02/05)
2
8
 
3
9
  Enhancement:
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # fluent-format
1
+ # fluent-format [![Build Status](https://secure.travis-ci.org/sonots/fluent-format.png?branch=master)](http://travis-ci.org/sonots/fluent-format)
2
2
 
3
3
  A command line utility to format fluentd configuration beautifully
4
4
 
@@ -34,7 +34,7 @@ require 'fluent-format'
34
34
 
35
35
  File.open(path) {|config|
36
36
  puts Fluent::Format.format(config) # formatted string
37
- puts Fluent::Format.check(config, plugin_dir) #=> true: success false: failure
37
+ Fluent::Format.check(config, plugin_dir) #=> Fluent::ConfigParseError or Fluent::ConfigError if failed
38
38
  }
39
39
  ```
40
40
 
@@ -0,0 +1,15 @@
1
+ class Fluent::ExampleOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('example', self)
3
+
4
+ config_param :param, :string, :default => nil
5
+
6
+ def configure(conf)
7
+ super
8
+
9
+ raise Fluent::ConfigError, "bad param" if @param == "bad"
10
+ end
11
+
12
+ def emit(tag, es, chain)
13
+ chain.next
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ <match **>
2
+ type example
3
+ param bad
4
+ </match>
File without changes
data/lib/fluent/format.rb CHANGED
@@ -1,4 +1,4 @@
1
- $log = Fluent::Log.new(STDERR, Fluent::Log::LEVEL_WARN)
1
+ $log = Fluent::Log.new($stderr, Fluent::Log::LEVEL_WARN)
2
2
 
3
3
  module Fluent
4
4
  class Format
@@ -30,12 +30,14 @@ module Fluent
30
30
  # @raise Fluent::ConfigError if plugin raises config error
31
31
  # @return true if success
32
32
  def run
33
- Fluent::Supervisor.new(@opts).ext_dry_run
33
+ Fluent::Supervisor.new(@opts).extended_dry_run
34
34
  end
35
35
  end
36
36
  end
37
37
  end
38
38
 
39
+ # lib/fluent/supervisor.rb
40
+ # Open the existing class and define new methods
39
41
  module Fluent
40
42
  class Supervisor
41
43
  # Extended to accept IO object
@@ -43,8 +45,8 @@ module Fluent
43
45
  # @raise Fluent::ConfigParseError if conf has syntax errors
44
46
  # @raise Fluent::ConfigError if plugin raises config error
45
47
  # @return true if success
46
- def ext_dry_run
47
- ext_read_config
48
+ def extended_dry_run
49
+ extended_read_config
48
50
  change_privilege
49
51
  init_engine
50
52
  install_main_process_signal_handlers
@@ -53,7 +55,7 @@ module Fluent
53
55
  end
54
56
 
55
57
  # Extended to accept IO object
56
- def ext_read_config
58
+ def extended_read_config
57
59
  if @config_path.respond_to?(:read) # IO object
58
60
  @config_data = @config_path.read
59
61
  else
@@ -11,7 +11,7 @@ module Fluent
11
11
  config = @options[:config]
12
12
  taputs Fluent::Format.format(config)
13
13
  rescue => e
14
- $log.error "#{e.class}: #{e}"
14
+ $stderr.puts "#{e.class} #{e.message} #{e.backtrace.first}"
15
15
  exit 1
16
16
  end
17
17
 
@@ -23,7 +23,7 @@ module Fluent
23
23
  plugin = @options[:plugin]
24
24
  Fluent::Format.check(config, plugin)
25
25
  rescue => e
26
- $log.error "#{e.class}: #{e}"
26
+ $stderr.puts "#{e.class} #{e.message} #{e.backtrace.first}"
27
27
  exit 1
28
28
  end
29
29
 
@@ -13,32 +13,14 @@ module Fluent
13
13
  # @raise Fluent::ConfigParseError if conf has syntax errors
14
14
  # @return [String] the formatted config
15
15
  def run
16
- config = read_config(@config_dev)
17
- indent_config(config)
16
+ config = Fluent::ExtConfig.read(@config_dev)
17
+ indent(config)
18
18
  end
19
19
 
20
20
  private
21
21
 
22
- # partial copy from lib/fluent/config.rb
23
- def read_config(dev)
24
- if dev.respond_to?(:read) # IO object
25
- parse_config(dev, '-', '-')
26
- else
27
- File.open(dev) {|io| parse_config(io, File.basename(dev), File.dirname(dev)) }
28
- end
29
- end
30
-
31
- # partial copy from lib/fluent/config.rb
32
- def parse_config(io, fname, basepath=Dir.pwd)
33
- if fname =~ /\.rb$/
34
- Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
35
- else
36
- Fluent::Config.parse(io, fname, basepath)
37
- end
38
- end
39
-
40
22
  # hmm, ugly workaround
41
- def indent_config(conf)
23
+ def indent(conf)
42
24
  lines = conf.to_s.split("\n")[1..-2] # remove <ROOT> and </ROOT>
43
25
  lines = lines.map {|line| line[2..-1] } # remove heading 2 white spaces
44
26
  lines.join("\n")
@@ -46,3 +28,34 @@ module Fluent
46
28
  end
47
29
  end
48
30
  end
31
+
32
+ # lib/fluent/config.rb
33
+ module Fluent
34
+ module ExtConfig
35
+ # Extended to accept IO object
36
+ #
37
+ # @raise Fluent::ConfigParseError if conf has syntax errors
38
+ # @raise Fluent::ConfigError if plugin raises config error
39
+ # @return [String] parsed config string
40
+ def self.read(dev)
41
+ if dev.respond_to?(:read) # IO object
42
+ parse(dev, '-', '-')
43
+ else
44
+ File.open(dev) {|io| parse(io, File.basename(dev), File.dirname(dev)) }
45
+ end
46
+ end
47
+
48
+ # Extended to accept config dsl
49
+ #
50
+ # @raise Fluent::ConfigParseError if conf has syntax errors
51
+ # @raise Fluent::ConfigError if plugin raises config error
52
+ # @return [String] parsed config string
53
+ def self.parse(io, fname, basepath=Dir.pwd)
54
+ if fname =~ /\.rb$/
55
+ Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
56
+ else
57
+ Fluent::Config.parse(io, fname, basepath)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,5 @@
1
1
  module Fluent
2
2
  class Format
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Fluent::Format::Check do
4
- let(:subject) { Fluent::Format.check(config) }
4
+ let(:plugin_dir) { File.expand_path('../../../example', File.dirname(__FILE__)) }
5
+ let(:subject) { Fluent::Format.check(config, plugin_dir) }
5
6
 
6
7
  context "valid" do
7
8
  let(:config) { StringIO.new(%[<match>\ntype stdout\n</match>]) }
@@ -17,5 +18,10 @@ describe Fluent::Format::Check do
17
18
  let(:config) { StringIO.new(%[<match>\ntype foobar\n</match>]) }
18
19
  it { expect { subject }.to raise_error(Fluent::ConfigError) }
19
20
  end
21
+
22
+ context "param error" do
23
+ let(:config) { StringIO.new(%[<match>\ntype example\nparam bad\n</match>]) }
24
+ it { expect { subject }.to raise_error(Fluent::ConfigError) }
25
+ end
20
26
  end
21
27
 
@@ -4,16 +4,29 @@ require 'fluent/format/cli'
4
4
  describe Fluent::Format::CLI do
5
5
  let(:cli) { Fluent::Format::CLI.new }
6
6
 
7
+ def capture_stderr
8
+ $stderr = StringIO.new
9
+ begin
10
+ yield
11
+ rescue SystemExit
12
+ end
13
+ return $stderr.string
14
+ ensure
15
+ $stderr = STDERR
16
+ end
17
+
7
18
  context "#format" do
8
19
  let(:subject) { cli.invoke(:format, [], opts) }
9
20
 
10
21
  context "success" do
11
22
  let(:opts) { {config: "fluent.conf"} }
23
+ it { capture_stderr { subject }.should == "" }
12
24
  it { expect { subject }.not_to raise_error }
13
25
  end
14
26
 
15
27
  context "failure" do
16
28
  let(:opts) { {config: "unknown.conf"} }
29
+ it { capture_stderr { subject }.should include "No such file or directory" }
17
30
  it { expect { subject }.to raise_error(SystemExit) }
18
31
  end
19
32
  end
@@ -23,11 +36,25 @@ describe Fluent::Format::CLI do
23
36
 
24
37
  context "success" do
25
38
  let(:opts) { {config: "fluent.conf"} }
39
+ it { capture_stderr { subject }.should == "" }
26
40
  it { expect { subject }.not_to raise_error }
27
41
  end
28
42
 
29
- context "failure" do
30
- let(:opts) { {config: "unknown.conf"} }
43
+ context "syntax error" do
44
+ let(:opts) { {config: "example/syntax_error.conf"} }
45
+ it { capture_stderr { subject }.should include("parse error") }
46
+ it { expect { subject }.to raise_error(SystemExit) }
47
+ end
48
+
49
+ context "plugin error" do
50
+ let(:opts) { {config: "example/plugin_error.conf"} }
51
+ it { capture_stderr { subject }.should include("Unknown input plugin") }
52
+ it { expect { subject }.to raise_error(SystemExit) }
53
+ end
54
+
55
+ context "param error" do
56
+ let(:opts) { {config: "example/param_error.conf", plugin: "example"} }
57
+ it { capture_stderr { subject }.should include("out_example.rb") }
31
58
  it { expect { subject }.to raise_error(SystemExit) }
32
59
  end
33
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -111,8 +111,10 @@ files:
111
111
  - README.md
112
112
  - Rakefile
113
113
  - bin/fluent-format
114
+ - example/out_example.rb
115
+ - example/param_error.conf
116
+ - example/plugin_error.conf
114
117
  - example/syntax_error.conf
115
- - example/unknown_plugin.conf
116
118
  - fluent-format.gemspec
117
119
  - fluent.conf
118
120
  - lib/fluent-format.rb