fluent-plugin-file-sprintf 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 461995197ed18e81301acc69c98ad8528f00d145
4
- data.tar.gz: 31ad074c45df03671ec1c6c8b4239cae5dfc6194
3
+ metadata.gz: 2e4c794378a0121131dbd3723bb922833cecae2c
4
+ data.tar.gz: 36c2bdcb67c8fbd0af4e74697fc04b5c6602297a
5
5
  SHA512:
6
- metadata.gz: 099c346032f98edb0229c42cb05873a13f98cd3e98cb64a385685663aa29e50b58bf1b5e66b97183549d9c03dcb6088fe7d5c647a1542a75838cd56cdbfbb66c
7
- data.tar.gz: 8fed8950f13f9cf90e0123127544fe700bfb13de83a47f347b30d4eee188db99bdbdcb4383779be77f9b9d61e367790f74d75b39a2bf57c1cfa65ab65dfc12a9
6
+ metadata.gz: 4935b43e8919108ed0db80c3716f30fc1a4bd8de615baf0c26b1173bdaefdf0bf025fc89cf2c4ad562573bd4b1eb9f52539245fac98f766e810a099c04be97a6
7
+ data.tar.gz: 9387b6a0fb6ed47c88fd05ab6eea5f55469d0298450570eee9413b69e631c0223a01a5bb3cee39b8173b54beddddf6f16f151a96ba028193cca39a6cce34de42
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # fluent-plugin-file-sprintf
1
+ # fluent-plugin-file-sprintf, a plugin for [Fluentd](http://fluentd.org)
2
2
 
3
3
  sprintf output file plugin for Fluentd.
4
4
 
@@ -30,6 +30,7 @@ include_tag_key|tag key in record|true
30
30
  tag_key_name|tag key name(default:tag)|tag_name
31
31
  include_time_key|time key in record|true
32
32
  time_key_name|time key name(default:time)|timestamp
33
+ rotate|rotate (default:true)|false
33
34
  rotate_format|file rotate format(default:%Y%m%d)|%Y%m%d
34
35
 
35
36
  ## key_names reserved words
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-file-sprintf"
7
- spec.version = "0.0.5"
7
+ spec.version = "0.0.6"
8
8
  spec.authors = ["Hiroshi Toyama"]
9
9
  spec.email = ["toyama0919@gmail.com"]
10
10
  spec.description = %q{sprintf output file plugin for Fluentd.}
@@ -5,15 +5,16 @@ module Fluent
5
5
 
6
6
  config_param :path, :string
7
7
  config_param :format, :string
8
- config_param :compress, :bool, :default => true
9
- config_param :include_tag_key, :bool, :default => false
10
- config_param :tag_key_name, :string, :default => "tag"
11
- config_param :include_time_key, :bool, :default => false
12
- config_param :time_key_name, :string, :default => "time"
8
+ config_param :compress, :bool, default: true
9
+ config_param :include_tag_key, :bool, default: false
10
+ config_param :tag_key_name, :string, default: 'tag'
11
+ config_param :include_time_key, :bool, default: false
12
+ config_param :time_key_name, :string, default: 'time'
13
13
  config_param :key_names, :string
14
- config_param :time_format, :string, :default => "%Y-%m-%d %H:%M:%S"
15
- config_param :rotate_format, :string, :default => "%Y%m%d"
16
- config_param :file_prefix_key, :string, :default => "Time.at(time).strftime(@rotate_format)"
14
+ config_param :time_format, :string, default: '%Y-%m-%d %H:%M:%S'
15
+ config_param :rotate, :bool, default: true
16
+ config_param :rotate_format, :string, default: '%Y%m%d'
17
+ config_param :file_prefix_key, :string, default: 'Time.at(time).strftime(@rotate_format)'
17
18
 
18
19
  def initialize
19
20
  super
@@ -32,9 +33,9 @@ module Fluent
32
33
 
33
34
  def configure(conf)
34
35
  super
35
- @key_names = @key_names.split(',').map{|key|
36
+ @key_names = @key_names.split(',').map do|key|
36
37
  key = key.strip
37
- result = ""
38
+ result = ''
38
39
  if key == 'time'
39
40
  result = "Time.at(time).strftime('#{@time_format}')"
40
41
  elsif key == 'tag'
@@ -49,7 +50,7 @@ module Fluent
49
50
  result = "record['" + key + "']"
50
51
  end
51
52
  result
52
- }
53
+ end
53
54
  @key_names = @key_names.join(',')
54
55
  @eval_string = "%Q{#{@format}} % [#{@key_names}]"
55
56
  $log.info "format => #{@eval_string}"
@@ -67,8 +68,12 @@ module Fluent
67
68
  end
68
69
 
69
70
  def write(chunk)
70
- write_file(chunk)
71
- compress_file
71
+ if @rotate
72
+ write_file(chunk)
73
+ compress_file if @compress
74
+ else
75
+ write_file_no_rotate(chunk)
76
+ end
72
77
  end
73
78
 
74
79
  private
@@ -79,9 +84,9 @@ module Fluent
79
84
  end
80
85
 
81
86
  filename_hash = {}
82
- set.each{|prefix|
83
- filename_hash[prefix] = File.open(@path + '.' + prefix,'a')
84
- }
87
+ set.each do|prefix|
88
+ filename_hash[prefix] = File.open(@path + '.' + prefix, 'a')
89
+ end
85
90
 
86
91
  chunk.msgpack_each do |tag, time, record|
87
92
  result = eval(@eval_string)
@@ -89,25 +94,31 @@ module Fluent
89
94
  file.puts result
90
95
  end
91
96
 
92
- filename_hash.each{|k,v|
97
+ filename_hash.each do|k, v|
93
98
  v.close
94
- }
99
+ end
95
100
  end
96
101
 
97
- def compress_file
98
- if @compress
99
- Dir.glob( "#{@path}.*[^gz]" ).each{ |output_path|
100
- if Time.now > File.mtime(output_path) + (@flush_interval * 5)
101
- Zlib::GzipWriter.open(output_path + ".gz") do |gz|
102
- gz.mtime = File.mtime(output_path)
103
- gz.orig_name = output_path
104
- gz.write IO.binread(output_path)
105
- end
106
- FileUtils.remove_file(output_path, force = true)
107
- end
108
- }
102
+ def write_file_no_rotate(chunk)
103
+ file = File.open(@path, 'a')
104
+ chunk.msgpack_each do |tag, time, record|
105
+ result = eval(@eval_string)
106
+ file.puts result
109
107
  end
108
+ file.close
110
109
  end
111
110
 
111
+ def compress_file
112
+ Dir.glob("#{@path}.*[^gz]").each do |output_path|
113
+ next if File.ftype(output_path) != 'file'
114
+ next if Time.now < (File.mtime(output_path) + (@flush_interval))
115
+ Zlib::GzipWriter.open(output_path + '.gz') do |gz|
116
+ gz.mtime = File.mtime(output_path)
117
+ gz.orig_name = output_path
118
+ gz.write IO.binread(output_path)
119
+ end
120
+ FileUtils.remove_file(output_path, force = true)
121
+ end
122
+ end
112
123
  end
113
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-file-sprintf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Toyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ltsv
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.2.0
89
+ rubygems_version: 2.2.2
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: sprintf output file plugin for Fluentd.