fluent-plugin-filter_linefeeder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +18 -0
- data/example.conf +14 -0
- data/fluent-plugin-filter_linefeeder.gemspec +25 -0
- data/lib/fluent/plugin/filter_linefeeder.rb +35 -0
- data/test/helper.rb +8 -0
- data/test/test_filter_linefeeder.rb +47 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66883b27b28fa3518b6999804326c7039493b617
|
4
|
+
data.tar.gz: b2661252f996455df9b74e7538353dc706758de3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8260a22c6cd57da7b7e6e6defc0d9050c240bcaa408f22df857fba740c7db21a84218d81409dd0d5edfc89058d84228de77791df73e669a55c5b3f1b3739eb02
|
7
|
+
data.tar.gz: f09a890ffb835e2b3faebdcd37d7acc50a84ebda4a0a1bc529c66fbb2ab9392003d1a72dc1f828846cba858785e78b8d65f4ad85c2d051ddfe6fffeb95130816
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Naotoshi Seo
|
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,47 @@
|
|
1
|
+
# fluent-plugin-filter_linefeeder
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-filter_linefeeder.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-filter_linefeeder)
|
4
|
+
|
5
|
+
A Fluentd filter plugin to convert '\n' to "\n" (line feed)
|
6
|
+
|
7
|
+
## What to do
|
8
|
+
|
9
|
+
I usually output rails application stacktrace logs with one line using my [oneline_log_formatter](https://github.com/sonots/oneline_log_formatter) so that I can easily collect logs.
|
10
|
+
This plugin recovers its '\n' strings into "\n" (line feed)
|
11
|
+
|
12
|
+
## Requirements
|
13
|
+
|
14
|
+
Fluentd >= v0.12
|
15
|
+
|
16
|
+
## Install
|
17
|
+
|
18
|
+
Use RubyGems:
|
19
|
+
|
20
|
+
```
|
21
|
+
gem install fluent-plugin-filter_linefeeder
|
22
|
+
```
|
23
|
+
|
24
|
+
## Configuration Example
|
25
|
+
|
26
|
+
See [example.conf](example.conf)
|
27
|
+
|
28
|
+
## Parameters
|
29
|
+
|
30
|
+
* keys
|
31
|
+
* record keys to target
|
32
|
+
|
33
|
+
## ChangeLog
|
34
|
+
|
35
|
+
See [CHANGELOG.md](CHANGELOG.md) for details.
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new [Pull Request](../../pull/new/master)
|
44
|
+
|
45
|
+
## Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2015 Naotoshi Seo. 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
|
data/example.conf
ADDED
@@ -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-filter_linefeeder"
|
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-filter_linefeeder"
|
10
|
+
s.summary = "A Fluentd filter plugin to convert '\n' to \"\n\" (line feed)"
|
11
|
+
s.description = s.summary
|
12
|
+
s.licenses = ["MIT"]
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency "fluentd", ">= 0.12"
|
20
|
+
s.add_runtime_dependency "string-scrub" if RUBY_VERSION.to_f < 2.1
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "test-unit"
|
23
|
+
s.add_development_dependency "pry"
|
24
|
+
s.add_development_dependency "pry-nav"
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fluent
|
2
|
+
class LinefeederFilter < Filter
|
3
|
+
Fluent::Plugin.register_filter('linefeeder', self)
|
4
|
+
|
5
|
+
config_param :keys do |val|
|
6
|
+
val.split(',')
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
require 'string/scrub' if RUBY_VERSION.to_f < 2.1
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(conf)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def filter(tag, time, record)
|
19
|
+
keys.each do |key|
|
20
|
+
linefeed!(record[key]) if record[key]
|
21
|
+
end
|
22
|
+
record
|
23
|
+
end
|
24
|
+
|
25
|
+
def linefeed!(string)
|
26
|
+
begin
|
27
|
+
string.gsub!("\\n", "\n")
|
28
|
+
rescue ArgumentError => e
|
29
|
+
raise e unless e.message.index("invalid byte sequence in") == 0
|
30
|
+
string.scrub!('?')
|
31
|
+
retry
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/plugin/filter_linefeeder'
|
3
|
+
|
4
|
+
class LinefeederFilterTest < Test::Unit::TestCase
|
5
|
+
include Fluent
|
6
|
+
|
7
|
+
setup do
|
8
|
+
Fluent::Test.setup
|
9
|
+
@time = Fluent::Engine.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_driver(conf = '')
|
13
|
+
Test::FilterTestDriver.new(LinefeederFilter).configure(conf, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def filter(d, msg)
|
17
|
+
d.run { d.filter(msg, @time) }
|
18
|
+
d.filtered_as_array.first[2]
|
19
|
+
end
|
20
|
+
|
21
|
+
sub_test_case 'configure' do
|
22
|
+
def test_keys
|
23
|
+
assert_raise Fluent::ConfigError do
|
24
|
+
create_driver('')
|
25
|
+
end
|
26
|
+
|
27
|
+
d = create_driver(%[keys a,b])
|
28
|
+
assert_equal ["a","b"], d.instance.keys
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
sub_test_case 'filter' do
|
33
|
+
def test_linefeed
|
34
|
+
d = create_driver(%[keys message])
|
35
|
+
msg = { 'message' => "foo\\nbar" }
|
36
|
+
filtered = filter(d, msg)
|
37
|
+
assert_equal "foo\nbar", filtered['message']
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_scrub
|
41
|
+
d = create_driver(%[keys message])
|
42
|
+
msg = { 'message' => "\xff".force_encoding('UTF-8') }
|
43
|
+
filtered = filter(d, msg)
|
44
|
+
assert_equal "?", filtered['message']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-filter_linefeeder
|
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: 2015-05-08 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.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
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: A Fluentd filter plugin to convert ' ' to " " (line feed)
|
84
|
+
email:
|
85
|
+
- sonots@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
|
+
- example.conf
|
98
|
+
- fluent-plugin-filter_linefeeder.gemspec
|
99
|
+
- lib/fluent/plugin/filter_linefeeder.rb
|
100
|
+
- test/helper.rb
|
101
|
+
- test/test_filter_linefeeder.rb
|
102
|
+
homepage: https://github.com/sonots/fluent-plugin-filter_linefeeder
|
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:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: A Fluentd filter plugin to convert ' ' to " " (line feed)
|
126
|
+
test_files:
|
127
|
+
- test/helper.rb
|
128
|
+
- test/test_filter_linefeeder.rb
|