fluent-plugin-color-stripper 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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +10 -0
- data/fluent-plugin-color-stripper.gemspec +24 -0
- data/lib/fluent/plugin/out_color_stripper.rb +55 -0
- data/test/test_color_stripper.rb +60 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9aa4b23ec2a3be836b31af80604b4ec83f88aff7
|
4
|
+
data.tar.gz: 4f9ed855efadc5d05e432d3ca164bd56bb370528
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1bb4d36f0e5c9306238cc24ef42da1c45fc0331ce0008379abb1840d405187b8407d4efc79e2971404bde4848963ce74b81f4a205b477279808521eaacc9b36
|
7
|
+
data.tar.gz: f726c7ae003a91dda548eb7873e13547943193eac08c602ba913d6c65706463da226042d0996a8a4caa0d846d5a234306be6300de06935ae30886ff8dbe5946f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ably
|
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,61 @@
|
|
1
|
+
# Fluent::Plugin::ColorStripper
|
2
|
+
|
3
|
+
An out plugin for [Fluentd](http://fluentd.org) to strip ANSI color from log files. No more nasty logs from apps that use color that appear similar to:
|
4
|
+
|
5
|
+
[0;33;49mWARN [0m : [0;33;49mRate limit of 6 notifications per hour met for Http monitor 'test' for 'server
|
6
|
+
'[0m
|
7
|
+
|
8
|
+
You can specify all or specific fields to have the ANSI color stripped
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
$ gem install fluent-plugin-color-stripper
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
<match input.tag>
|
17
|
+
type color_stripper
|
18
|
+
tag output.tag
|
19
|
+
strip_fields key1, key2
|
20
|
+
</match>
|
21
|
+
|
22
|
+
Pass this record:
|
23
|
+
|
24
|
+
input.tag: {
|
25
|
+
"key1": "\033[30mvalue1\033[0m",
|
26
|
+
"key2": "\033[31mvalue2\033[0m"
|
27
|
+
"key3": "\033[32mvalue3\033[0m"
|
28
|
+
}
|
29
|
+
|
30
|
+
Then you get:
|
31
|
+
|
32
|
+
output.tag: {
|
33
|
+
"key1": "value1",
|
34
|
+
"key2": "value2",
|
35
|
+
"key3": "\033[32mvalue3\033[0m"
|
36
|
+
}
|
37
|
+
|
38
|
+
### strip_fields
|
39
|
+
|
40
|
+
If the field `strip_fields` is omitted or is empty then all fields will have their color stripped.
|
41
|
+
|
42
|
+
<match input.tag>
|
43
|
+
type color_stripper
|
44
|
+
tag output.tag
|
45
|
+
</match>
|
46
|
+
|
47
|
+
Pass this record:
|
48
|
+
|
49
|
+
input.tag: {
|
50
|
+
"key1": "\033[30mvalue1\033[0m",
|
51
|
+
"key2": "\033[31mvalue2\033[0m"
|
52
|
+
"key3": "\033[32mvalue3\033[0m"
|
53
|
+
}
|
54
|
+
|
55
|
+
Then you get:
|
56
|
+
|
57
|
+
output.tag: {
|
58
|
+
"key1": "value1",
|
59
|
+
"key2": "value2",
|
60
|
+
"key3": "value2"
|
61
|
+
}
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-color-stripper"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Matthew O'Riordan"]
|
9
|
+
spec.email = ["matt@ably.io "]
|
10
|
+
spec.description = %q{Output plugin to strip ANSI color codes in the logs.}
|
11
|
+
spec.summary = %q{Output plugin to strip ANSI color codes in the logs.}
|
12
|
+
spec.homepage = "https://github.com/mattheworiordan/fluent-plugin-color-stripper"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10"
|
22
|
+
spec.add_development_dependency "colorize", "~> 0.7.5"
|
23
|
+
spec.add_runtime_dependency "fluentd", "~> 0.12"
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Fluent
|
2
|
+
class ColorStripperOutput < Output
|
3
|
+
Fluent::Plugin.register_output('color_stripper', self)
|
4
|
+
|
5
|
+
config_param :strip_fields, :string, default: nil
|
6
|
+
|
7
|
+
def configure(conf)
|
8
|
+
super
|
9
|
+
@strip_fields_arr = conf['strip_fields'].to_s.split(/\s*,\s*/).map do |field|
|
10
|
+
field unless field.strip.empty?
|
11
|
+
end.compact
|
12
|
+
end
|
13
|
+
|
14
|
+
def emit(tag, es, chain)
|
15
|
+
es.each do |time, record|
|
16
|
+
Engine.emit(@tag, time, format_record(record))
|
17
|
+
end
|
18
|
+
|
19
|
+
chain.next
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def format_record(record)
|
25
|
+
record.each_with_object({}) do |(key, val), object|
|
26
|
+
object[key] = if strip_field?(key)
|
27
|
+
uncolorize(val)
|
28
|
+
else
|
29
|
+
val
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Return uncolorized string
|
36
|
+
#
|
37
|
+
def uncolorize(string)
|
38
|
+
scan_for_colors(string).inject('') do |str, match|
|
39
|
+
str << (match[3] || match[4])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Scan for colorized string
|
45
|
+
#
|
46
|
+
def scan_for_colors(string)
|
47
|
+
string.scan(/\033\[([0-9]+);([0-9]+);([0-9]+)m(.+?)\033\[0m|([^\033]+)/m)
|
48
|
+
end
|
49
|
+
|
50
|
+
def strip_field?(field)
|
51
|
+
puts @strip_fields_arr
|
52
|
+
@strip_fields_arr.empty? || @strip_fields_arr.include?(field)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'fluent/test'
|
3
|
+
require 'fluent/plugin/out_color_stripper'
|
4
|
+
|
5
|
+
class ColorStripperOutputTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_driver(conf)
|
11
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ColorStripperOutput).configure(conf)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_selected_fields
|
15
|
+
d1 = create_driver %[
|
16
|
+
type color_stripper
|
17
|
+
tag formatted
|
18
|
+
strip_fields decolorize, decolorize_also
|
19
|
+
]
|
20
|
+
|
21
|
+
d1.run do
|
22
|
+
d1.emit({ 'keep_color' => 'red'.colorize(:red), 'decolorize' => 'green'.colorize(:green) })
|
23
|
+
d1.emit({ 'no_color' => 'no_color', 'decolorize_also' => 'yellow'.colorize(:yellow) })
|
24
|
+
end
|
25
|
+
|
26
|
+
assert_equal [
|
27
|
+
{
|
28
|
+
'keep_color' => 'red'.colorize(:red),
|
29
|
+
'decolorize' => 'green'
|
30
|
+
},
|
31
|
+
{
|
32
|
+
'no_color' => 'no_color',
|
33
|
+
'decolorize_also' => 'yellow'
|
34
|
+
}
|
35
|
+
], d1.records
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_all_fields
|
39
|
+
d1 = create_driver %[
|
40
|
+
type color_stripper
|
41
|
+
tag formatted
|
42
|
+
]
|
43
|
+
|
44
|
+
d1.run do
|
45
|
+
d1.emit({ 'color' => 'red'.colorize(:red), 'decolorize' => 'green'.colorize(:green) })
|
46
|
+
d1.emit({ 'no_color' => 'no_color', 'decolorize_also' => 'yellow'.colorize(:yellow) })
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_equal [
|
50
|
+
{
|
51
|
+
'color' => 'red',
|
52
|
+
'decolorize' => 'green'
|
53
|
+
},
|
54
|
+
{
|
55
|
+
'no_color' => 'no_color',
|
56
|
+
'decolorize_also' => 'yellow'
|
57
|
+
}
|
58
|
+
], d1.records
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-color-stripper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew O'Riordan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluentd
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.12'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.12'
|
69
|
+
description: Output plugin to strip ANSI color codes in the logs.
|
70
|
+
email:
|
71
|
+
- 'matt@ably.io '
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-color-stripper.gemspec
|
82
|
+
- lib/fluent/plugin/out_color_stripper.rb
|
83
|
+
- test/test_color_stripper.rb
|
84
|
+
homepage: https://github.com/mattheworiordan/fluent-plugin-color-stripper
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Output plugin to strip ANSI color codes in the logs.
|
108
|
+
test_files:
|
109
|
+
- test/test_color_stripper.rb
|
110
|
+
has_rdoc:
|