Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
Add :format => :json option
Browse files Browse the repository at this point in the history
  • Loading branch information
freeformz committed Jun 17, 2011
1 parent 9fc2c7d commit c388086
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/logglier/client.rb
@@ -1,3 +1,5 @@
require 'json'

module Logglier
module Client

Expand Down Expand Up @@ -57,8 +59,14 @@ def masher(hash, prefix=nil)

def formatter
proc do |severity, datetime, progname, msg|
message = "#{datetime} "
message << massage_message(msg, severity)
if @format == :json && msg.is_a?(Hash)
msg.merge!({ :severity => severity,
:datetime => datetime,
:progname => progname }).to_json
else
message = "#{datetime} "
message << massage_message(msg, severity)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/logglier/client/http.rb
@@ -1,4 +1,3 @@
require 'net/https'
require 'uri'

require File.join(File.dirname(__FILE__), 'http', 'sync')
Expand All @@ -13,6 +12,7 @@ class HTTP

def initialize(opts={})
setup_input_uri(opts)
@format = opts[:format].to_sym
@deliverer = if opts[:threaded]
Logglier::Client::HTTP::DeliveryThread.new(@input_uri, opts)
else
Expand Down
2 changes: 2 additions & 0 deletions lib/logglier/client/http/sync.rb
@@ -1,3 +1,5 @@
require 'net/https'

module Logglier
module Client
class HTTP
Expand Down
4 changes: 4 additions & 0 deletions spec/http_spec.rb
Expand Up @@ -20,8 +20,12 @@
@http.should_receive(:request_post).exactly(2).times.and_raise Errno::ECONNRESET
@proxy.deliver('message')
end

it "fails for other errors" do
@http.should_receive(:request_post).once.and_raise EOFError
@proxy.deliver('message')
end

describe "json format" do
end
end

0 comments on commit c388086

Please sign in to comment.