Skip to content

Commit

Permalink
Merge pull request #2721 from ganmacs/stdout-check-time-format
Browse files Browse the repository at this point in the history
Make time_format configurable in stdout format
  • Loading branch information
repeatedly authored Dec 10, 2019
2 parents 5165986 + 4d59c07 commit 3679233
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fluent/plugin/formatter_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StdoutFormatter < Formatter
def configure(conf)
super

@time_formatter = Strftime.new(TIME_FORMAT)
@time_formatter = Strftime.new(@time_format || TIME_FORMAT)
@sub_formatter = Plugin.new_formatter(@output_type, parent: self.owner)
@sub_formatter.configure(conf)
end
Expand Down
19 changes: 19 additions & 0 deletions test/plugin/test_out_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ def create_driver(conf = CONFIG)
end
end

test 'configure with time_format' do
d = create_driver(CONFIG + <<-CONF)
<format>
@type stdout
time_format %Y-%m-%dT%H:%M:%S.%L%z
</format>
CONF

time = event_time
out = capture_log do
d.run(default_tag: 'test') do
d.feed(time, {'test' => 'test'})
end
end

t = Time.at(time).localtime.strftime("%Y-%m-%dT%H:%M:%S.%L%z")
assert_equal "#{t} test: {\"test\":\"test\"}\n", out
end

test 'emit with default configuration' do
d = create_driver
time = event_time()
Expand Down

0 comments on commit 3679233

Please sign in to comment.