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

Add json formatter. #56

Merged
merged 1 commit into from
Nov 19, 2013
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
3 changes: 2 additions & 1 deletion lib/lograge.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'lograge/version'
require 'lograge/formatters/cee'
require 'lograge/formatters/json'
require 'lograge/formatters/graylog2'
require 'lograge/formatters/key_value'
require 'lograge/formatters/l2met'
Expand Down Expand Up @@ -39,7 +40,7 @@ def self.custom_options(event)
# - An object that responds to call with an event argument and returns
# true iff the event should be ignored.
#
# The action ignores are given to 'ignore_actions'. The callable ignores
# The action ignores are given to 'ignore_actions'. The callable ignores
# are given to 'ignore'. Both methods can be called multiple times, which
# just adds more ignore conditions to a list that is checked before logging.

Expand Down
10 changes: 10 additions & 0 deletions lib/lograge/formatters/json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'json'
module Lograge
module Formatters
class Json
def call(data)
::JSON.dump(data)
end
end
end
end
6 changes: 6 additions & 0 deletions spec/formatters/json_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'
require 'lograge'

describe Lograge::Formatters::Json do
it { expect( subject.call({ custom: 'data' })).to eq('{"custom":"data"}') }
end