fluentd 0.14.17-x64-mingw32 → 1.3.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -5
  3. data/ADOPTERS.md +5 -0
  4. data/{ChangeLog → CHANGELOG.md} +495 -6
  5. data/CONTRIBUTING.md +5 -2
  6. data/GOVERNANCE.md +55 -0
  7. data/LICENSE +202 -0
  8. data/MAINTAINERS.md +7 -5
  9. data/README.md +17 -10
  10. data/bin/fluent-ca-generate +6 -0
  11. data/example/counter.conf +18 -0
  12. data/example/secondary_file.conf +3 -2
  13. data/fluentd.gemspec +3 -3
  14. data/lib/fluent/agent.rb +1 -1
  15. data/lib/fluent/command/binlog_reader.rb +11 -2
  16. data/lib/fluent/command/ca_generate.rb +181 -0
  17. data/lib/fluent/command/cat.rb +28 -15
  18. data/lib/fluent/command/debug.rb +4 -4
  19. data/lib/fluent/command/fluentd.rb +2 -2
  20. data/lib/fluent/command/plugin_config_formatter.rb +24 -2
  21. data/lib/fluent/command/plugin_generator.rb +26 -8
  22. data/lib/fluent/config/configure_proxy.rb +7 -1
  23. data/lib/fluent/config/dsl.rb +8 -5
  24. data/lib/fluent/config/element.rb +5 -0
  25. data/lib/fluent/config/literal_parser.rb +7 -1
  26. data/lib/fluent/config/types.rb +28 -2
  27. data/lib/fluent/config/v1_parser.rb +1 -2
  28. data/lib/fluent/configurable.rb +1 -0
  29. data/lib/fluent/counter.rb +23 -0
  30. data/lib/fluent/counter/base_socket.rb +46 -0
  31. data/lib/fluent/counter/client.rb +297 -0
  32. data/lib/fluent/counter/error.rb +86 -0
  33. data/lib/fluent/counter/mutex_hash.rb +163 -0
  34. data/lib/fluent/counter/server.rb +273 -0
  35. data/lib/fluent/counter/store.rb +205 -0
  36. data/lib/fluent/counter/validator.rb +145 -0
  37. data/lib/fluent/env.rb +1 -0
  38. data/lib/fluent/event_router.rb +1 -1
  39. data/lib/fluent/log.rb +119 -29
  40. data/lib/fluent/plugin/base.rb +12 -0
  41. data/lib/fluent/plugin/buf_file.rb +20 -16
  42. data/lib/fluent/plugin/buffer.rb +130 -32
  43. data/lib/fluent/plugin/buffer/file_chunk.rb +23 -4
  44. data/lib/fluent/plugin/compressable.rb +1 -1
  45. data/lib/fluent/plugin/filter_grep.rb +135 -21
  46. data/lib/fluent/plugin/filter_parser.rb +13 -2
  47. data/lib/fluent/plugin/filter_record_transformer.rb +16 -14
  48. data/lib/fluent/plugin/formatter_stdout.rb +3 -2
  49. data/lib/fluent/plugin/formatter_tsv.rb +5 -1
  50. data/lib/fluent/plugin/in_debug_agent.rb +8 -1
  51. data/lib/fluent/plugin/in_forward.rb +1 -1
  52. data/lib/fluent/plugin/in_http.rb +84 -3
  53. data/lib/fluent/plugin/in_monitor_agent.rb +7 -1
  54. data/lib/fluent/plugin/in_syslog.rb +31 -10
  55. data/lib/fluent/plugin/in_tail.rb +142 -53
  56. data/lib/fluent/plugin/in_tcp.rb +5 -6
  57. data/lib/fluent/plugin/in_udp.rb +6 -2
  58. data/lib/fluent/plugin/in_unix.rb +1 -1
  59. data/lib/fluent/plugin/multi_output.rb +1 -0
  60. data/lib/fluent/plugin/out_copy.rb +25 -2
  61. data/lib/fluent/plugin/out_file.rb +26 -7
  62. data/lib/fluent/plugin/out_forward.rb +81 -42
  63. data/lib/fluent/plugin/out_secondary_file.rb +2 -2
  64. data/lib/fluent/plugin/out_stdout.rb +0 -1
  65. data/lib/fluent/plugin/out_stream.rb +1 -1
  66. data/lib/fluent/plugin/output.rb +221 -57
  67. data/lib/fluent/plugin/parser_apache.rb +1 -1
  68. data/lib/fluent/plugin/parser_apache2.rb +5 -1
  69. data/lib/fluent/plugin/parser_apache_error.rb +1 -1
  70. data/lib/fluent/plugin/parser_json.rb +10 -3
  71. data/lib/fluent/plugin/parser_ltsv.rb +7 -0
  72. data/lib/fluent/plugin/parser_multiline.rb +2 -1
  73. data/lib/fluent/plugin/parser_nginx.rb +1 -1
  74. data/lib/fluent/plugin/parser_none.rb +1 -0
  75. data/lib/fluent/plugin/parser_regexp.rb +15 -14
  76. data/lib/fluent/plugin/parser_syslog.rb +9 -5
  77. data/lib/fluent/plugin_helper.rb +2 -0
  78. data/lib/fluent/plugin_helper/cert_option.rb +28 -9
  79. data/lib/fluent/plugin_helper/compat_parameters.rb +3 -1
  80. data/lib/fluent/plugin_helper/counter.rb +51 -0
  81. data/lib/fluent/plugin_helper/event_loop.rb +9 -0
  82. data/lib/fluent/plugin_helper/record_accessor.rb +210 -0
  83. data/lib/fluent/plugin_helper/retry_state.rb +15 -7
  84. data/lib/fluent/plugin_helper/server.rb +87 -25
  85. data/lib/fluent/plugin_helper/socket_option.rb +5 -2
  86. data/lib/fluent/plugin_helper/timer.rb +8 -7
  87. data/lib/fluent/root_agent.rb +18 -9
  88. data/lib/fluent/supervisor.rb +63 -23
  89. data/lib/fluent/system_config.rb +30 -2
  90. data/lib/fluent/test/helpers.rb +1 -1
  91. data/lib/fluent/time.rb +15 -7
  92. data/lib/fluent/timezone.rb +26 -2
  93. data/lib/fluent/version.rb +1 -1
  94. data/templates/new_gem/README.md.erb +2 -2
  95. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +1 -1
  96. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +1 -1
  97. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +1 -1
  98. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +4 -4
  99. data/test/command/test_ca_generate.rb +70 -0
  100. data/test/command/test_fluentd.rb +2 -2
  101. data/test/command/test_plugin_config_formatter.rb +8 -7
  102. data/test/command/test_plugin_generator.rb +65 -39
  103. data/test/config/test_config_parser.rb +7 -2
  104. data/test/config/test_configurable.rb +7 -2
  105. data/test/config/test_configure_proxy.rb +41 -3
  106. data/test/config/test_dsl.rb +10 -10
  107. data/test/config/test_element.rb +10 -0
  108. data/test/config/test_literal_parser.rb +8 -0
  109. data/test/config/test_plugin_configuration.rb +56 -0
  110. data/test/config/test_system_config.rb +19 -1
  111. data/test/config/test_types.rb +37 -0
  112. data/test/counter/test_client.rb +559 -0
  113. data/test/counter/test_error.rb +44 -0
  114. data/test/counter/test_mutex_hash.rb +179 -0
  115. data/test/counter/test_server.rb +589 -0
  116. data/test/counter/test_store.rb +258 -0
  117. data/test/counter/test_validator.rb +137 -0
  118. data/test/plugin/test_buf_file.rb +124 -0
  119. data/test/plugin/test_buffer.rb +3 -2
  120. data/test/plugin/test_filter_grep.rb +580 -2
  121. data/test/plugin/test_filter_parser.rb +33 -2
  122. data/test/plugin/test_filter_record_transformer.rb +22 -1
  123. data/test/plugin/test_formatter_ltsv.rb +3 -0
  124. data/test/plugin/test_formatter_tsv.rb +68 -0
  125. data/test/plugin/test_in_debug_agent.rb +21 -0
  126. data/test/plugin/test_in_exec.rb +3 -5
  127. data/test/plugin/test_in_http.rb +178 -0
  128. data/test/plugin/test_in_monitor_agent.rb +1 -1
  129. data/test/plugin/test_in_syslog.rb +64 -0
  130. data/test/plugin/test_in_tail.rb +116 -6
  131. data/test/plugin/test_in_tcp.rb +21 -0
  132. data/test/plugin/test_in_udp.rb +78 -0
  133. data/test/plugin/test_metadata.rb +89 -0
  134. data/test/plugin/test_out_copy.rb +31 -0
  135. data/test/plugin/test_out_file.rb +108 -2
  136. data/test/plugin/test_out_forward.rb +195 -2
  137. data/test/plugin/test_out_secondary_file.rb +14 -0
  138. data/test/plugin/test_output.rb +159 -45
  139. data/test/plugin/test_output_as_buffered.rb +19 -0
  140. data/test/plugin/test_output_as_buffered_backup.rb +307 -0
  141. data/test/plugin/test_output_as_buffered_retries.rb +70 -0
  142. data/test/plugin/test_output_as_buffered_secondary.rb +1 -1
  143. data/test/plugin/test_parser_apache2.rb +1 -0
  144. data/test/plugin/test_parser_labeled_tsv.rb +17 -0
  145. data/test/plugin/test_parser_nginx.rb +40 -0
  146. data/test/plugin/test_parser_regexp.rb +6 -7
  147. data/test/plugin/test_parser_syslog.rb +155 -5
  148. data/test/plugin_helper/test_child_process.rb +4 -4
  149. data/test/plugin_helper/test_compat_parameters.rb +22 -0
  150. data/test/plugin_helper/test_record_accessor.rb +197 -0
  151. data/test/plugin_helper/test_retry_state.rb +20 -0
  152. data/test/plugin_helper/test_server.rb +30 -2
  153. data/test/test_config.rb +3 -3
  154. data/test/test_configdsl.rb +2 -2
  155. data/test/test_log.rb +51 -1
  156. data/test/test_root_agent.rb +33 -0
  157. data/test/test_supervisor.rb +105 -0
  158. metadata +68 -8
  159. data/COPYING +0 -14
@@ -17,6 +17,7 @@
17
17
  require 'fileutils'
18
18
 
19
19
  require 'fluent/config'
20
+ require 'fluent/counter'
20
21
  require 'fluent/env'
21
22
  require 'fluent/engine'
22
23
  require 'fluent/error'
@@ -41,6 +42,8 @@ module Fluent
41
42
  module ServerModule
42
43
  def before_run
43
44
  @start_time = Time.now
45
+ @rpc_server = nil
46
+ @counter = nil
44
47
 
45
48
  if config[:rpc_endpoint]
46
49
  @rpc_endpoint = config[:rpc_endpoint]
@@ -54,6 +57,10 @@ module Fluent
54
57
  install_windows_event_handler
55
58
  end
56
59
 
60
+ if counter = config[:counter_server]
61
+ run_counter_server(counter)
62
+ end
63
+
57
64
  socket_manager_path = ServerEngine::SocketManager::Server.generate_path
58
65
  ServerEngine::SocketManager::Server.open(socket_manager_path)
59
66
  ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
@@ -61,6 +68,7 @@ module Fluent
61
68
 
62
69
  def after_run
63
70
  stop_rpc_server if @rpc_endpoint
71
+ stop_counter_server if @counter
64
72
  Fluent::Supervisor.cleanup_resources
65
73
  end
66
74
 
@@ -126,6 +134,18 @@ module Fluent
126
134
  @rpc_server.shutdown
127
135
  end
128
136
 
137
+ def run_counter_server(counter_conf)
138
+ @counter = Fluent::Counter::Server.new(
139
+ counter_conf.scope,
140
+ {host: counter_conf.bind, port: counter_conf.port, log: $log, path: counter_conf.backup_path}
141
+ )
142
+ @counter.start
143
+ end
144
+
145
+ def stop_counter_server
146
+ @counter.stop
147
+ end
148
+
129
149
  def install_supervisor_signal_handlers
130
150
  trap :HUP do
131
151
  $log.debug "fluentd supervisor process get SIGHUP"
@@ -160,21 +180,31 @@ module Fluent
160
180
 
161
181
  def supervisor_sigusr1_handler
162
182
  if log = config[:logger_initializer]
163
- log.reopen!
183
+ # Creating new thread due to mutex can't lock
184
+ # in main thread during trap context
185
+ Thread.new {
186
+ log.reopen!
187
+ }.run
164
188
  end
165
189
 
166
- if pid = config[:worker_pid]
167
- Process.kill(:USR1, pid)
168
- # don't rescue Erro::ESRSH here (invalid status)
190
+ if config[:worker_pid]
191
+ config[:worker_pid].each_value do |pid|
192
+ Process.kill(:USR1, pid)
193
+ # don't rescue Errno::ESRCH here (invalid status)
194
+ end
169
195
  end
170
196
  end
171
197
 
172
198
  def kill_worker
173
- if pid = config[:worker_pid]
174
- if Fluent.windows?
175
- Process.kill :KILL, pid
176
- else
177
- Process.kill :TERM, pid
199
+ if config[:worker_pid]
200
+ pids = config[:worker_pid].clone
201
+ config[:worker_pid].clear
202
+ pids.each_value do |pid|
203
+ if Fluent.windows?
204
+ Process.kill :KILL, pid
205
+ else
206
+ Process.kill :TERM, pid
207
+ end
178
208
  end
179
209
  end
180
210
  end
@@ -198,7 +228,7 @@ module Fluent
198
228
  end
199
229
 
200
230
  def after_start
201
- config[:worker_pid] = @pm.pid
231
+ (config[:worker_pid] ||= {})[@worker_id] = @pm.pid
202
232
  end
203
233
  end
204
234
 
@@ -218,7 +248,8 @@ module Fluent
218
248
 
219
249
  config_fname = File.basename(path)
220
250
  config_basedir = File.dirname(path)
221
- config_data = File.read(path)
251
+ # Assume fluent.conf encoding is UTF-8
252
+ config_data = File.open(path, "r:utf-8:utf-8") {|f| f.read }
222
253
  inline_config = params['inline_config']
223
254
  if inline_config == '-'
224
255
  config_data << "\n" << STDIN.read
@@ -242,6 +273,7 @@ module Fluent
242
273
  log_rotate_size = params['log_rotate_size']
243
274
  rpc_endpoint = system_config.rpc_endpoint
244
275
  enable_get_dump = system_config.enable_get_dump
276
+ counter_server = system_config.counter_server
245
277
 
246
278
  log_opts = {suppress_repeated_stacktrace: suppress_repeated_stacktrace}
247
279
  logger_initializer = Supervisor::LoggerInitializer.new(
@@ -283,6 +315,7 @@ module Fluent
283
315
  suppress_repeated_stacktrace: suppress_repeated_stacktrace,
284
316
  daemonize: daemonize,
285
317
  rpc_endpoint: rpc_endpoint,
318
+ counter_server: counter_server,
286
319
  enable_get_dump: enable_get_dump,
287
320
  windows_daemon_cmdline: [ServerEngine.ruby_bin_path,
288
321
  File.join(File.dirname(__FILE__), 'daemon.rb'),
@@ -359,6 +392,11 @@ module Fluent
359
392
  self
360
393
  end
361
394
 
395
+ def apply_options(opts)
396
+ $log.format = opts[:format] if opts[:format]
397
+ $log.time_format = opts[:time_format] if opts[:time_format]
398
+ end
399
+
362
400
  def level=(level)
363
401
  @level = level
364
402
  $log.level = level
@@ -438,6 +476,9 @@ module Fluent
438
476
  show_plugin_config if @show_plugin_config
439
477
  read_config
440
478
  set_system_config
479
+ @log.apply_options(format: @system_config.log.format, time_format: @system_config.log.time_format)
480
+
481
+ $log.info :supervisor, "parsing config file is succeeded", path: @config_path
441
482
 
442
483
  if @workers < 1
443
484
  raise Fluent::ConfigError, "invalid number of workers (must be > 0):#{@workers}"
@@ -484,11 +525,12 @@ module Fluent
484
525
  else :workers
485
526
  end
486
527
  @log.init(process_type, worker_id)
487
- Process.setproctitle("worker:#{@process_name}") if @process_name
488
-
489
528
  show_plugin_config if @show_plugin_config
490
529
  read_config
491
530
  set_system_config
531
+ @log.apply_options(format: @system_config.log.format, time_format: @system_config.log.time_format)
532
+
533
+ Process.setproctitle("worker:#{@process_name}") if @process_name
492
534
 
493
535
  if @standalone_worker && @workers != 1
494
536
  raise Fluent::ConfigError, "invalid number of workers (must be 1 or unspecified) with --no-supervisor: #{@workers}"
@@ -497,11 +539,11 @@ module Fluent
497
539
  install_main_process_signal_handlers
498
540
 
499
541
  # This is the only log messsage for @standalone_worker
500
- $log.info "starting fluentd-#{Fluent::VERSION} without supervision", pid: Process.pid if @standalone_worker
542
+ $log.info "starting fluentd-#{Fluent::VERSION} without supervision", pid: Process.pid, ruby: RUBY_VERSION if @standalone_worker
501
543
 
502
544
  main_process do
503
545
  create_socket_manager if @standalone_worker
504
- change_privilege
546
+ change_privilege if @standalone_worker
505
547
  init_engine
506
548
  run_configure
507
549
  run_engine
@@ -519,7 +561,7 @@ module Fluent
519
561
  end
520
562
 
521
563
  def dry_run_cmd
522
- $log.info "starting fluentd-#{Fluent::VERSION} as dry run mode"
564
+ $log.info "starting fluentd-#{Fluent::VERSION} as dry run mode", ruby: RUBY_VERSION
523
565
  @system_config.suppress_config_dump = true
524
566
  dry_run
525
567
  exit 0
@@ -555,7 +597,7 @@ module Fluent
555
597
  dry_run
556
598
 
557
599
  Process.setproctitle("supervisor:#{@process_name}") if @process_name
558
- $log.info "starting fluentd-#{Fluent::VERSION}", pid: Process.pid
600
+ $log.info "starting fluentd-#{Fluent::VERSION}", pid: Process.pid, ruby: RUBY_VERSION
559
601
 
560
602
  rubyopt = ENV["RUBYOPT"]
561
603
  fluentd_spawn_cmd = [ServerEngine.ruby_bin_path, "-Eascii-8bit:ascii-8bit"]
@@ -647,14 +689,13 @@ module Fluent
647
689
  end
648
690
 
649
691
  def flush_buffer
650
- $log.debug "fluentd main process get SIGUSR1"
651
- $log.info "force flushing buffered events"
652
- @log.reopen!
653
-
654
692
  # Creating new thread due to mutex can't lock
655
693
  # in main thread during trap context
656
694
  Thread.new {
657
695
  begin
696
+ $log.debug "fluentd main process get SIGUSR1"
697
+ $log.info "force flushing buffered events"
698
+ @log.reopen!
658
699
  Fluent::Engine.flush!
659
700
  $log.debug "flushing thread: flushed"
660
701
  rescue Exception => e
@@ -714,10 +755,9 @@ module Fluent
714
755
  end
715
756
 
716
757
  def read_config
717
- $log.info :supervisor, "reading config file", path: @config_path
718
758
  @config_fname = File.basename(@config_path)
719
759
  @config_basedir = File.dirname(@config_path)
720
- @config_data = File.read(@config_path)
760
+ @config_data = File.open(@config_path, "r:utf-8:utf-8") {|f| f.read }
721
761
  if @inline_config == '-'
722
762
  @config_data << "\n" << STDIN.read
723
763
  elsif @inline_config
@@ -26,7 +26,7 @@ module Fluent
26
26
  :suppress_repeated_stacktrace, :emit_error_log_interval, :suppress_config_dump,
27
27
  :log_event_verbose,
28
28
  :without_source, :rpc_endpoint, :enable_get_dump, :process_name,
29
- :file_permission, :dir_permission,
29
+ :file_permission, :dir_permission, :counter_server, :counter_client,
30
30
  ]
31
31
 
32
32
  config_param :workers, :integer, default: 1
@@ -46,6 +46,32 @@ module Fluent
46
46
  config_param :dir_permission, default: nil do |v|
47
47
  v.to_i(8)
48
48
  end
49
+ config_section :log, required: false, init: true, multi: false do
50
+ config_param :format, :enum, list: [:text, :json], default: :text
51
+ config_param :time_format, :string, default: '%Y-%m-%d %H:%M:%S %z'
52
+ end
53
+
54
+ config_section :counter_server, multi: false do
55
+ desc 'scope name of counter server'
56
+ config_param :scope, :string
57
+
58
+ desc 'the port of counter server to listen to'
59
+ config_param :port, :integer, default: nil
60
+ desc 'the bind address of counter server to listen to'
61
+ config_param :bind, :string, default: nil
62
+
63
+ desc 'backup file path of counter values'
64
+ config_param :backup_path, :string
65
+ end
66
+
67
+ config_section :counter_client, multi: false do
68
+ desc 'the port of counter server'
69
+ config_param :port, :integer, default: nil
70
+ desc 'the IP address or hostname of counter server'
71
+ config_param :host, :string
72
+ desc 'the timeout of each operation'
73
+ config_param :timeout, :time, default: nil
74
+ end
49
75
 
50
76
  def self.create(conf)
51
77
  systems = conf.elements(name: 'system')
@@ -94,7 +120,7 @@ module Fluent
94
120
  supervisor.instance_eval {
95
121
  SYSTEM_CONFIG_PARAMETERS.each do |param|
96
122
  case param
97
- when :rpc_endpoint, :enable_get_dump, :process_name, :file_permission, :dir_permission
123
+ when :rpc_endpoint, :enable_get_dump, :process_name, :file_permission, :dir_permission, :counter_server, :counter_client
98
124
  next # doesn't exist in command line options
99
125
  when :emit_error_log_interval
100
126
  system.emit_error_log_interval = @suppress_interval if @suppress_interval
@@ -132,6 +158,8 @@ module Fluent
132
158
  instance_variable_set("@#{param}", param_value)
133
159
  end
134
160
  end
161
+ #@counter_server = system.counter_server unless system.counter_server.nil?
162
+ #@counter_client = system.counter_client unless system.counter_client.nil?
135
163
  }
136
164
  end
137
165
 
@@ -21,7 +21,7 @@ require 'fluent/time'
21
21
  module Fluent
22
22
  module Test
23
23
  module Helpers
24
- # See "Example Custom Assertion: http://test-unit.github.io/test-unit/en/Test/Unit/Assertions.html
24
+ # See "Example Custom Assertion: https://test-unit.github.io/test-unit/en/Test/Unit/Assertions.html
25
25
  def assert_equal_event_time(expected, actual, message = nil)
26
26
  expected_s = "#{Time.at(expected.sec)} (nsec #{expected.nsec})"
27
27
  actual_s = "#{Time.at(actual.sec) } (nsec #{actual.nsec})"
@@ -24,6 +24,7 @@ require 'fluent/config/error'
24
24
  module Fluent
25
25
  class EventTime
26
26
  TYPE = 0
27
+ FORMATTER = Strftime.new('%Y-%m-%d %H:%M:%S.%N %z')
27
28
 
28
29
  def initialize(sec, nsec = 0)
29
30
  @sec = sec
@@ -108,6 +109,10 @@ module Fluent
108
109
  def method_missing(name, *args, &block)
109
110
  @sec.send(name, *args, &block)
110
111
  end
112
+
113
+ def inspect
114
+ FORMATTER.exec(Time.at(self))
115
+ end
111
116
  end
112
117
 
113
118
  module TimeMixin
@@ -319,21 +324,24 @@ module Fluent
319
324
  @tc2 = 0
320
325
  @tc2_str = nil
321
326
 
327
+ strftime = format && (Strftime.new(format) rescue nil)
322
328
  if format && format =~ /(^|[^%])(%%)*%L|(^|[^%])(%%)*%\d*N/
323
329
  define_singleton_method(:format, method(:format_with_subsec))
324
330
  define_singleton_method(:call, method(:format_with_subsec))
325
331
  else
326
332
  define_singleton_method(:format, method(:format_without_subsec))
327
- define_singleton_method(:call, method(:format_with_subsec))
333
+ define_singleton_method(:call, method(:format_without_subsec))
328
334
  end
329
335
 
330
- formatter = Fluent::Timezone.formatter(timezone, format)
336
+ formatter = Fluent::Timezone.formatter(timezone, strftime ? strftime : format)
331
337
  @format_nocache = case
332
- when formatter then formatter
333
- when format && localtime then ->(time){ Time.at(time).strftime(format) }
334
- when format then ->(time){ Time.at(time).utc.strftime(format) }
335
- when localtime then ->(time){ Time.at(time).iso8601 }
336
- else ->(time){ Time.at(time).utc.iso8601 }
338
+ when formatter then formatter
339
+ when strftime && localtime then ->(time){ strftime.exec(Time.at(time)) }
340
+ when format && localtime then ->(time){ Time.at(time).strftime(format) }
341
+ when strftime then ->(time){ strftime.exec(Time.at(time).utc) }
342
+ when format then ->(time){ Time.at(time).utc.strftime(format) }
343
+ when localtime then ->(time){ Time.at(time).iso8601 }
344
+ else ->(time){ Time.at(time).utc.iso8601 }
337
345
  end
338
346
  end
339
347
 
@@ -97,10 +97,15 @@ module Fluent
97
97
  if NUMERIC_PATTERN === timezone
98
98
  offset = Time.zone_offset(timezone)
99
99
 
100
- if format
100
+ case
101
+ when format.is_a?(String)
101
102
  return Proc.new {|time|
102
103
  Time.at(time).localtime(offset).strftime(format)
103
104
  }
105
+ when format.is_a?(Strftime)
106
+ return Proc.new {|time|
107
+ format.exec(Time.at(time).localtime(offset))
108
+ }
104
109
  else
105
110
  return Proc.new {|time|
106
111
  Time.at(time).localtime(offset).iso8601
@@ -116,10 +121,15 @@ module Fluent
116
121
  return nil
117
122
  end
118
123
 
119
- if format
124
+ case
125
+ when format.is_a?(String)
120
126
  return Proc.new {|time|
121
127
  Time.at(time).localtime(tz.period_for_utc(time).utc_total_offset).strftime(format)
122
128
  }
129
+ when format.is_a?(Strftime)
130
+ return Proc.new {|time|
131
+ format.exec(Time.at(time).localtime(tz.period_for_utc(time).utc_total_offset))
132
+ }
123
133
  else
124
134
  return Proc.new {|time|
125
135
  Time.at(time).localtime(tz.period_for_utc(time).utc_total_offset).iso8601
@@ -129,5 +139,19 @@ module Fluent
129
139
 
130
140
  return nil
131
141
  end
142
+
143
+ def self.utc_offset(timezone)
144
+ return 0 if timezone.nil?
145
+
146
+ case timezone
147
+ when NUMERIC_PATTERN
148
+ Time.zone_offset(timezone)
149
+ when NAME_PATTERN
150
+ tz = TZInfo::Timezone.get(timezone)
151
+ ->(time) {
152
+ tz.period_for_utc(time).utc_total_offset
153
+ }
154
+ end
155
+ end
132
156
  end
133
157
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '0.14.17'
19
+ VERSION = '1.3.1'
20
20
 
21
21
  end
@@ -1,6 +1,6 @@
1
1
  # <%= gem_name %>
2
2
 
3
- [Fluentd](http://fluentd.org/) <%= type %> plugin to do something.
3
+ [Fluentd](https://fluentd.org/) <%= type %> plugin to do something.
4
4
 
5
5
  TODO: write description for you plugin.
6
6
 
@@ -31,7 +31,7 @@ $ bundle
31
31
  You can generate configuration template:
32
32
 
33
33
  ```
34
- $ fluent-plugin-format-config <%= type %> <%= name %>
34
+ $ fluent-plugin-config-format <%= type %> <%= name %>
35
35
  ```
36
36
 
37
37
  You can copy and paste generated documents here.
@@ -5,7 +5,7 @@ require "fluent/plugin/filter"
5
5
  module Fluent
6
6
  module Plugin
7
7
  class <%= class_name %> < Fluent::Plugin::Filter
8
- Fluent::Plugin.register_filter("<%= name %>", self)
8
+ Fluent::Plugin.register_filter("<%= plugin_name %>", self)
9
9
 
10
10
  def filter(tag, time, record)
11
11
  end
@@ -5,7 +5,7 @@ require "fluent/plugin/input"
5
5
  module Fluent
6
6
  module Plugin
7
7
  class <%= class_name %> < Fluent::Plugin::Input
8
- Fluent::Plugin.register_input("<%= name %>", self)
8
+ Fluent::Plugin.register_input("<%= plugin_name %>", self)
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ require "fluent/plugin/output"
5
5
  module Fluent
6
6
  module Plugin
7
7
  class <%= class_name %> < Fluent::Plugin::Output
8
- Fluent::Plugin.register_output("<%= name %>", self)
8
+ Fluent::Plugin.register_output("<%= plugin_name %>", self)
9
9
  end
10
10
  end
11
11
  end