Skip to content

Commit

Permalink
Support logging any object (Fixes #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwbutler committed Oct 5, 2014
1 parent e68043b commit 420a973
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/logstash-logger/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def build_event(message, severity, time)
when Hash
event_data = data.merge("@timestamp" => time)
LogStash::Event.new(event_data)
when String
LogStash::Event.new("message" => data, "@timestamp" => time)
else
LogStash::Event.new("message" => msg2str(data), "@timestamp" => time)
end

event['severity'] ||= severity
Expand Down
15 changes: 15 additions & 0 deletions spec/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,20 @@
expect(listener_event['host']).to eq(hostname)
expect(listener_event['@timestamp']).to_not be_nil
end

it 'takes any object as input and writes a logstash event' do
message = Time.now

expect(logdev).to receive(:write).and_call_original do |event|
expect(event).to be_a LogStash::Event
expect(event.host).to eql(hostname)
expect(event['message']).to eql(message.inspect)
expect(event['severity']).to eql('INFO')
end

logger.info(message)

expect(listener_event['message']).to eq(message.inspect)
end

end

0 comments on commit 420a973

Please sign in to comment.