fluent-plugin-stdout_ex 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5d9c7f8995e802b5f9932cf0cb6c5b8e06315a9
4
+ data.tar.gz: aaf0526219d97294ea957405b0540d5b29d870d9
5
+ SHA512:
6
+ metadata.gz: bdde4cdbc9c12208d6206cc280575e7beae33a914e03c2dceaa47f847660bf9e94ec1176aa4f1663e01fbf56237b7d6c8c81934ec9cab77f0adc0618e8b10762
7
+ data.tar.gz: 8d889d39a9830f49ddcddea8a245c2ee3c492420d68b9a020e1d24b7eb2f7066f83c4a921ed2249b16e0e977f882d4bde730e3abaa2c4381d0764c7a07ebb2c9
@@ -0,0 +1,13 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ .yardoc
12
+ .ruby-version
13
+ pkg/*
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.*
5
+ gemfile:
6
+ - Gemfile
@@ -0,0 +1,4 @@
1
+ ## 0.0.1
2
+
3
+ First version
4
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Same with Fluentd
@@ -0,0 +1,57 @@
1
+ # fluent-plugin-stdout_ex
2
+
3
+ Fluentd out\_stdout extension
4
+
5
+ ## Introduction
6
+
7
+ Although the original `out_stdout` outputs log messages as:
8
+
9
+ ```
10
+ 2010-05-04 12:02:01 +0900 test: {"test":"test"}
11
+ ```
12
+
13
+ this plugin outputs log messages as:
14
+
15
+ ```
16
+ 2014-05-02 02:02:21 +0900 [info]: 2010-05-04 12:02:01 +0900 test: {"test":"test"}
17
+ ```
18
+
19
+ where the first time expresses the current time of *logging*, and the second time expresses the time field of messages, i.e.,
20
+ the time when the message is created or, the time written in application logs.
21
+
22
+ This behavior is very useful because we can see the latency between receiving (logging) and sending (creating) of messages.
23
+
24
+ ## Configuration
25
+
26
+ ```apache
27
+ <match **>
28
+ type stdout_ex
29
+ </match>
30
+ ```
31
+
32
+ ## Parameters
33
+
34
+ Basically same with out\_stdout plugin. See http://docs.fluentd.org/articles/out_stdout
35
+
36
+ * format ltsv
37
+
38
+ The output becomes LTSV format as followings:
39
+
40
+ current_time:2010-05-04 12:02:01 +0900 time:2010-05-04 12:02:01 +0900 tag:test record:{"test":"test"}
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new [Pull Request](../../pull/new/master)
49
+
50
+ ## ChangeLog
51
+
52
+ See [CHANGELOG.md](CHANGELOG.md) for details.
53
+
54
+ ## stdoutright
55
+
56
+ * Copyright (c) 2014- Naotoshi Seo
57
+ * See [LICENSE](LICENSE) for details.
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/*.rb'
8
+ test.verbose = true
9
+ end
10
+ task :default => :test
11
+
12
+ desc 'Open an irb session preloaded with the gem library'
13
+ task :console do
14
+ sh 'irb -rubygems -I lib'
15
+ end
16
+ task :c => :console
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-stdout_ex"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Naotoshi Seo"]
8
+ s.email = ["sonots@gmail.com"]
9
+ s.homepage = "https://github.com/sonots/fluent-plugin-stdout_ex"
10
+ s.summary = "Fluentd out_stdout extension"
11
+ s.description = s.summary
12
+ s.licenses = ["MIT"]
13
+
14
+ s.rubyforge_project = "fluent-plugin-stdout_ex"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "fluentd"
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "pry"
24
+ s.add_development_dependency "pry-nav"
25
+ end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+ class StdoutExOutput < Output
20
+ Plugin.register_output('stdout_ex', self)
21
+
22
+ OUTPUT_PROCS = {
23
+ :json => Proc.new {|record| Yajl.dump(record) },
24
+ :hash => Proc.new {|record| record.to_s },
25
+ }
26
+
27
+ config_param :output_type, :default => :json do |val|
28
+ case val.downcase
29
+ when 'json'
30
+ :json
31
+ when 'hash'
32
+ :hash
33
+ else
34
+ raise ConfigError, "stdout output output_type should be 'json' or 'hash'"
35
+ end
36
+ end
37
+ config_param :format, :type => :string, :default => nil
38
+
39
+ def configure(conf)
40
+ super
41
+ @output_proc = OUTPUT_PROCS[@output_type]
42
+ @format_proc =
43
+ if @format == "ltsv"
44
+ Proc.new {|time, tag, record| "current_time:#{Time.now.localtime}\ttime:#{Time.at(time).localtime}\ttag:#{tag}\trecord:#{@output_proc.call(record)}\n" }
45
+ else
46
+ # [info]: is a fake ;-)
47
+ Proc.new {|time, tag, record| "#{Time.now.localtime} [info]: #{Time.at(time).localtime} #{tag}: #{@output_proc.call(record)}\n" }
48
+ end
49
+ end
50
+
51
+ def emit(tag, es, chain)
52
+ es.each {|time,record|
53
+ $log.write @format_proc.call(time, tag, record)
54
+ }
55
+ $log.flush
56
+
57
+ chain.next
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ require 'fluent/plugin/out_stdout_ex'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,72 @@
1
+ require 'fluent/test'
2
+
3
+ class StdoutExOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ ]
10
+
11
+ def create_driver(conf = CONFIG)
12
+ Fluent::Test::OutputTestDriver.new(Fluent::StdoutExOutput).configure(conf)
13
+ end
14
+
15
+ def test_configure
16
+ d = create_driver
17
+ assert_equal :json, d.instance.output_type
18
+ end
19
+
20
+ def test_configure_output_type
21
+ d = create_driver(CONFIG + "\noutput_type json")
22
+ assert_equal :json, d.instance.output_type
23
+
24
+ d = create_driver(CONFIG + "\noutput_type hash")
25
+ assert_equal :hash, d.instance.output_type
26
+
27
+ assert_raise(Fluent::ConfigError) do
28
+ d = create_driver(CONFIG + "\noutput_type foo")
29
+ end
30
+ end
31
+
32
+ def test_emit_json
33
+ d = create_driver(CONFIG + "\noutput_type json")
34
+ time = Time.now
35
+ out = capture_log { d.emit({'test' => 'test'}, time) }
36
+ assert_equal "#{time.localtime} [info]: #{time.localtime} test: {\"test\":\"test\"}\n", out
37
+
38
+ # NOTE: Float::NAN is not jsonable
39
+ assert_raise(Yajl::EncodeError) { d.emit({'test' => Float::NAN}, time) }
40
+ end
41
+
42
+ def test_emit_hash
43
+ d = create_driver(CONFIG + "\noutput_type hash")
44
+ time = Time.now
45
+ out = capture_log { d.emit({'test' => 'test'}, time) }
46
+ assert_equal "#{time.localtime} [info]: #{time.localtime} test: {\"test\"=>\"test\"}\n", out
47
+
48
+ # NOTE: Float::NAN is not jsonable, but hash string can output it.
49
+ out = capture_log { d.emit({'test' => Float::NAN}, time) }
50
+ assert_equal "#{time.localtime} [info]: #{time.localtime} test: {\"test\"=>NaN}\n", out
51
+ end
52
+
53
+ def test_emit_ltsv
54
+ d = create_driver(CONFIG + "\nformat ltsv")
55
+ time = Time.now
56
+ out = capture_log { d.emit({'test' => 'test'}, time) }
57
+ assert_equal "current_time:#{time.localtime}\ttime:#{time.localtime}\ttag:test\trecord:{\"test\":\"test\"}\n", out
58
+ end
59
+
60
+ private
61
+
62
+ # Capture the log output of the block given
63
+ def capture_log(&block)
64
+ tmp = $log
65
+ $log = StringIO.new
66
+ yield
67
+ return $log.string
68
+ ensure
69
+ $log = tmp
70
+ end
71
+ end
72
+
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-stdout_ex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-nav
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Fluentd out_stdout extension
70
+ email:
71
+ - sonots@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - fluent-plugin-stdout_ex.gemspec
84
+ - lib/fluent/plugin/out_stdout_ex.rb
85
+ - test/helper.rb
86
+ - test/plugin/test_out_stdout_ex.rb
87
+ homepage: https://github.com/sonots/fluent-plugin-stdout_ex
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project: fluent-plugin-stdout_ex
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Fluentd out_stdout extension
111
+ test_files:
112
+ - test/helper.rb
113
+ - test/plugin/test_out_stdout_ex.rb