fluent-plugin-formatter_sprintf 0.0.1 → 0.0.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: 02096918dee431715480041b7b23f0040680191e
4
- data.tar.gz: 92220382a6186a03b5dc37dc703d3edaac121cbd
3
+ metadata.gz: 5675b240999ae98824ca04a279b71c761cc7ab1b
4
+ data.tar.gz: 9c2cbc6f59ce9b2abdefd0e6cb79b5e6c0791dd7
5
5
  SHA512:
6
- metadata.gz: ef617634e2246ce43a034caef558a629af61f0832073f81065fd88bed4abc4ec52542dd9476a0c10884678ed201e8c2a4ef95f97b7b37f2cc3cd67742512915b
7
- data.tar.gz: 27495d9dfd9f7a088878320110905450de30106351d4805464ba6ad71fadbaa7a25079c2277b6dd50f92ab27a542d9ea848620955d742281b5898758b0cc1091
6
+ metadata.gz: 0dfbd9fa5a68e6587818b352b0f63b0b5d73756714ae90f6153314bd2892ec999359f49b9abb2c2d930405d79d0bce5ee792f3bd72acca3debfcc91c6c0c3a8a
7
+ data.tar.gz: 21887079b92d92c83f8b426a4b94507ea4117dee35f17f26d938718eb0968f786a37d94803005dcf378ffe0a30748f5e11778659391d1056f4793c24c70ea54a
data/.travis.yml CHANGED
@@ -4,3 +4,4 @@ rvm:
4
4
  - 2.1
5
5
  gemfile:
6
6
  - Gemfile
7
+ script: "rake test"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fluent-plugin-formatter_sprintf
2
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)
3
+ [![Build Status](https://secure.travis-ci.org/toyama0919/fluent-plugin-formatter_sprintf.png?branch=master)](http://travis-ci.org/toyama0919/fluent-plugin-formatter_sprintf)
4
4
 
5
5
  Fluentd sprintf formatter plugin
6
6
 
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-formatter_sprintf"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Hiroshi Toyama"]
8
8
  s.email = ["toyama0919@gmail.com"]
9
9
  s.homepage = "https://github.com/toyama0919/fluent-plugin-formatter_sprintf"
@@ -7,6 +7,8 @@ module Fluent
7
7
  include HandleTagAndTimeMixin
8
8
 
9
9
  config_param :sprintf_format, :string
10
+ config_param :sprintf_blank_string, :string, :default => nil
11
+ config_param :sprintf_blank_record_format, :string, :default => nil
10
12
 
11
13
  def initialize
12
14
  super
@@ -18,6 +20,11 @@ module Fluent
18
20
  r = /\$\{([^}]+)\}/
19
21
  @keys = @sprintf_format.scan(r).map{ |key| key.first }
20
22
  @sprintf_format = @sprintf_format.gsub(/\$\{([^}]+)\}/, '%s')
23
+ if @sprintf_blank_record_format
24
+ @sprintf_blank_record_keys = @sprintf_blank_record_format.scan(r).map{ |key| key.first }
25
+ @sprintf_blank_record_format = @sprintf_blank_record_format.gsub(/\$\{([^}]+)\}/, '%s')
26
+ end
27
+
21
28
  begin
22
29
  @sprintf_format % @keys
23
30
  rescue ArgumentError => e
@@ -26,16 +33,22 @@ module Fluent
26
33
  end
27
34
 
28
35
  def format(tag, time, record)
29
- values = @keys.map{ |key|
36
+ if record.empty? && @sprintf_blank_record_format
37
+ return @sprintf_blank_record_format % get_values(@sprintf_blank_record_keys, tag, time, record)
38
+ end
39
+ @sprintf_format % get_values(@keys, tag, time, record)
40
+ end
41
+
42
+ def get_values(keys, tag, time, record)
43
+ keys.map{ |key|
30
44
  if key == 'tag'
31
45
  tag
32
46
  elsif key == 'time'
33
47
  Time.at(time).strftime(@time_format)
34
48
  else
35
- record[key]
49
+ record[key] || @sprintf_blank_string
36
50
  end
37
51
  }
38
- @sprintf_format % values
39
52
  end
40
53
  end
41
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-formatter_sprintf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Toyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -126,3 +126,4 @@ summary: Fluentd Free formatter plugin, Use sprintf.
126
126
  test_files:
127
127
  - test/helper.rb
128
128
  - test/test_formatter_sprintf.rb
129
+ has_rdoc: