fluent-plugin-formatter_sprintf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02096918dee431715480041b7b23f0040680191e
4
+ data.tar.gz: 92220382a6186a03b5dc37dc703d3edaac121cbd
5
+ SHA512:
6
+ metadata.gz: ef617634e2246ce43a034caef558a629af61f0832073f81065fd88bed4abc4ec52542dd9476a0c10884678ed201e8c2a4ef95f97b7b37f2cc3cd67742512915b
7
+ data.tar.gz: 27495d9dfd9f7a088878320110905450de30106351d4805464ba6ad71fadbaa7a25079c2277b6dd50f92ab27a542d9ea848620955d742281b5898758b0cc1091
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ coverage
12
+ .yardoc
13
+ .ruby-version
14
+ pkg/*
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1
5
+ gemfile:
6
+ - Gemfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.0.1
2
+
3
+ First version
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hiroshi Toyama
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # fluent-plugin-formatter_sprintf
2
+
3
+ [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-formatter_sprintf.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-formatter_sprintf)
4
+
5
+ Fluentd sprintf formatter plugin
6
+
7
+ ## Install
8
+
9
+ Use RubyGems:
10
+
11
+ ```
12
+ gem install fluent-plugin-formatter_sprintf
13
+ ```
14
+
15
+ ## Configuration Example
16
+
17
+ `out_file` and `out_s3` plugin supports formatter plugin.
18
+
19
+ ### out_file
20
+
21
+ ```apache
22
+ <match test.file>
23
+ type file
24
+ path /tmp/test.log
25
+ format sprintf
26
+ sprintf_format "${tag} ${time} ${url} ${ip_address}\n"
27
+ time_format "%Y-%m-%d %H:%M:%S"
28
+ </match>
29
+ ```
30
+
31
+ ### out_s3
32
+
33
+ ```apache
34
+ <match test.s3>
35
+ type s3
36
+
37
+ aws_key_id XXXXXXXXXXXXXXXXXX
38
+ aws_sec_key XXXXXXXXXXXXXXXXXX
39
+ s3_bucket sample-bucket
40
+ s3_object_key_format %{path}%{time_slice}%{index}
41
+ path logs/
42
+ buffer_path /tmp/fluent/s3
43
+ buffer_chunk_limit 8m
44
+
45
+ time_slice_format %Y/%m/%d/test.log.%H%M
46
+ time_slice_wait 1m
47
+ time_format %Y-%m-%d %H:%M:%S,%3N
48
+ store_as text
49
+
50
+ format sprintf
51
+ sprintf_format "${tag} ${time} ${url} ${ip_address}\n"
52
+
53
+ </match>
54
+ ```
55
+
56
+ ### bad syntax(at error)
57
+
58
+ sprintf_format "%s ${tag} ${time} ${url} ${ip_address}\n"
59
+
60
+
61
+ ## ChangeLog
62
+
63
+ See [CHANGELOG.md](CHANGELOG.md) for details.
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create new [Pull Request](../../pull/new/master)
72
+
73
+ ## Copyright
74
+
75
+ Copyright (c) 2014 Hiroshi Toyama. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ desc 'Run test_unit based test'
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.test_files = Dir["test/**/test_*.rb"].sort
9
+ t.verbose = true
10
+ #t.warning = true
11
+ end
12
+ task :default => :test
13
+
14
+ desc 'Open an irb session preloaded with the gem library'
15
+ task :console do
16
+ sh 'irb -rubygems -I lib'
17
+ end
18
+ task :c => :console
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "fluent-plugin-formatter_sprintf"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Hiroshi Toyama"]
8
+ s.email = ["toyama0919@gmail.com"]
9
+ s.homepage = "https://github.com/toyama0919/fluent-plugin-formatter_sprintf"
10
+ s.summary = "Fluentd Free formatter plugin, Use sprintf."
11
+ s.description = s.summary
12
+ s.licenses = ["MIT"]
13
+
14
+ s.rubyforge_project = "fluent-plugin-formatter_sprintf"
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 "test-unit"
24
+ s.add_development_dependency "pry"
25
+ s.add_development_dependency "pry-nav"
26
+ end
@@ -0,0 +1,42 @@
1
+ module Fluent
2
+ module TextFormatter
3
+ class SprintfFormatter < Formatter
4
+ Plugin.register_formatter('sprintf', self)
5
+
6
+ include Configurable
7
+ include HandleTagAndTimeMixin
8
+
9
+ config_param :sprintf_format, :string
10
+
11
+ def initialize
12
+ super
13
+ end
14
+
15
+ def configure(conf)
16
+ super
17
+ @time_format = @time_format || '%Y-%m-%d %H:%M:%S'
18
+ r = /\$\{([^}]+)\}/
19
+ @keys = @sprintf_format.scan(r).map{ |key| key.first }
20
+ @sprintf_format = @sprintf_format.gsub(/\$\{([^}]+)\}/, '%s')
21
+ begin
22
+ @sprintf_format % @keys
23
+ rescue ArgumentError => e
24
+ raise Fluent::ConfigError, "formatter_sprintf: @sprintf_format is can't include '%'"
25
+ end
26
+ end
27
+
28
+ def format(tag, time, record)
29
+ values = @keys.map{ |key|
30
+ if key == 'tag'
31
+ tag
32
+ elsif key == 'time'
33
+ Time.at(time).strftime(@time_format)
34
+ else
35
+ record[key]
36
+ end
37
+ }
38
+ @sprintf_format % values
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ <match test.file>
2
+ type file
3
+ path /tmp/test.log
4
+ format sprintf
5
+ sprintf_format "${tag} ${time} ${url} ${ip_address}\n"
6
+ time_format "%Y-%m-%d_%H:%M:%S"
7
+ </match>
data/test/helper.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'fluent/log'
3
+ require 'fluent/test'
4
+
5
+ unless defined?(Test::Unit::AssertionFailedError)
6
+ class Test::Unit::AssertionFailedError < StandardError
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'helper'
2
+ require 'fluent/formatter'
3
+ require 'fluent/plugin/formatter_sprintf'
4
+
5
+ class SprintfFormatterTest < ::Test::Unit::TestCase
6
+ def setup
7
+ @formatter = Fluent::Plugin.new_formatter('sprintf')
8
+ @time = Fluent::Engine.now
9
+ end
10
+
11
+ def configure(conf)
12
+ end
13
+
14
+ def test_format_space
15
+ @formatter.configure({'sprintf_format' => "${tag} ${url} ${ip_address}\n"})
16
+ tag = 'file.test'
17
+ record = {"url" => "/", "ip_address" => "127.0.0.1"}
18
+
19
+ formatted = @formatter.format(tag, @time, record)
20
+ assert_equal("file.test / 127.0.0.1\n", formatted)
21
+ end
22
+
23
+ def test_format_tsv
24
+ @formatter.configure({'sprintf_format' => "${tag}\t${url}\t${ip_address}\n"})
25
+ tag = 'file.test'
26
+ record = {"url" => "/", "ip_address" => "127.0.0.1"}
27
+
28
+ formatted = @formatter.format(tag, @time, record)
29
+ assert_equal("file.test\t/\t127.0.0.1\n", formatted)
30
+ end
31
+
32
+ def test_format_literal_error
33
+ assert_raise(Fluent::ConfigError) do
34
+ @formatter.configure({'sprintf_format' => "%s\t${url}\t${ip_address}\n"})
35
+ end
36
+
37
+ assert_raise(Fluent::ConfigError) do
38
+ @formatter.configure({'sprintf_format' => "${url}\t${ip_address}\t%s"})
39
+ end
40
+
41
+ assert_raise(Fluent::ConfigError) do
42
+ @formatter.configure({'sprintf_format' => "${url}\t%s\t${ip_address}\t"})
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-formatter_sprintf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi Toyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 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: test-unit
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
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
+ - !ruby/object:Gem::Dependency
70
+ name: pry-nav
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Fluentd Free formatter plugin, Use sprintf.
84
+ email:
85
+ - toyama0919@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - fluent-plugin-formatter_sprintf.gemspec
98
+ - lib/fluent/plugin/formatter_sprintf.rb
99
+ - sample/fluent.conf
100
+ - test/helper.rb
101
+ - test/test_formatter_sprintf.rb
102
+ homepage: https://github.com/toyama0919/fluent-plugin-formatter_sprintf
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project: fluent-plugin-formatter_sprintf
122
+ rubygems_version: 2.4.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Fluentd Free formatter plugin, Use sprintf.
126
+ test_files:
127
+ - test/helper.rb
128
+ - test/test_formatter_sprintf.rb