Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make time_format configurable in stdout format #2721

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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