Skip to content

Commit

Permalink
Merge pull request #56 from i0rek/json_formatter
Browse files Browse the repository at this point in the history
Add json formatter.
  • Loading branch information
roidrage committed Nov 19, 2013
2 parents f3f243b + c7b5acd commit 063a5b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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

0 comments on commit 063a5b4

Please sign in to comment.