logglier 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/logglier/client.rb +8 -1
 - data/lib/logglier/client/syslog.rb +14 -4
 - data/lib/logglier/version.rb +1 -1
 - data/spec/client/syslog_spec.rb +29 -1
 - data/spec/spec_helper.rb +21 -7
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1dcb0781ee2e961054577527a6105aa85fd6e02c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 75437a8852a4b155379c9e9b1876d26ff14e6023
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 92d4f3c3eaf6d65a6670d6f8178988b615df3d838a7223affcaefe88c4c5b2c47c2837a6f3a6f68c98ffd460788468b3438a246fa8ef0fd3212e6ac8e24c4f6a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 16cced1160ddb78a516b9655ce1bff2d97aeba9c252befe390d1c3f99949bb810bc0a2bdb99f066b88961255daa24f56e6d3dad575c8e5ed90df07c3dd3634da
         
     | 
    
        data/lib/logglier/client.rb
    CHANGED
    
    | 
         @@ -74,7 +74,14 @@ module Logglier 
     | 
|
| 
       74 
74 
     | 
    
         | 
| 
       75 
75 
     | 
    
         
             
                  def massage_message(incoming_message, severity, processid)
         
     | 
| 
       76 
76 
     | 
    
         
             
                    outgoing_message = ""
         
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                    # Append PID and severity to message, unless we're a Syslog
         
     | 
| 
      
 79 
     | 
    
         
            +
                    # client. If we're a Syslog client, that information is already
         
     | 
| 
      
 80 
     | 
    
         
            +
                    # in the Syslog packet.
         
     | 
| 
      
 81 
     | 
    
         
            +
                    unless self.is_a?(Logglier::Client::Syslog)
         
     | 
| 
      
 82 
     | 
    
         
            +
                      outgoing_message << "pid=#{processid}, severity=#{severity}, "
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
       78 
85 
     | 
    
         
             
                    case incoming_message
         
     | 
| 
       79 
86 
     | 
    
         
             
                    when Hash
         
     | 
| 
       80 
87 
     | 
    
         
             
                      outgoing_message << masher(incoming_message)
         
     | 
| 
         @@ -9,7 +9,7 @@ module Logglier 
     | 
|
| 
       9 
9 
     | 
    
         
             
                class Syslog
         
     | 
| 
       10 
10 
     | 
    
         
             
                  include Logglier::Client::InstanceMethods
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                  attr_reader :input_uri, :facility, :syslog
         
     | 
| 
      
 12 
     | 
    
         
            +
                  attr_reader :input_uri, :facility, :format, :syslog
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                  def initialize(opts={})
         
     | 
| 
       15 
15 
     | 
    
         
             
                    setup_input_uri(opts)
         
     | 
| 
         @@ -35,6 +35,7 @@ module Logglier 
     | 
|
| 
       35 
35 
     | 
    
         
             
                      @facility = 16
         
     | 
| 
       36 
36 
     | 
    
         
             
                    end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
      
 38 
     | 
    
         
            +
                    @format = opts[:format]
         
     | 
| 
       38 
39 
     | 
    
         
             
                    @hostname = opts[:hostname] || Socket.gethostname.split('.').first
         
     | 
| 
       39 
40 
     | 
    
         
             
                  end
         
     | 
| 
       40 
41 
     | 
    
         | 
| 
         @@ -81,12 +82,21 @@ module Logglier 
     | 
|
| 
       81 
82 
     | 
    
         
             
                    proc do |severity, datetime, progname, msg|
         
     | 
| 
       82 
83 
     | 
    
         
             
                      processid=Process.pid
         
     | 
| 
       83 
84 
     | 
    
         
             
                      message = "<#{pri(severity)}>#{datetime.strftime(datetime_format)} #{@hostname} "
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                      # Include process ID in progname/log tag - RFC3164 § 5.3
         
     | 
| 
       84 
87 
     | 
    
         
             
                      if progname
         
     | 
| 
       85 
     | 
    
         
            -
                        message << "#{progname}: "
         
     | 
| 
      
 88 
     | 
    
         
            +
                        message << "#{progname}[#{processid}]: "
         
     | 
| 
       86 
89 
     | 
    
         
             
                      else
         
     | 
| 
       87 
     | 
    
         
            -
                        message << "#{$0}: "
         
     | 
| 
      
 90 
     | 
    
         
            +
                        message << "#{$0}[#{processid}]: "
         
     | 
| 
       88 
91 
     | 
    
         
             
                      end
         
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                      # Support logging JSON to Syslog
         
     | 
| 
      
 94 
     | 
    
         
            +
                      if @format == :json && msg.is_a?(Hash)
         
     | 
| 
      
 95 
     | 
    
         
            +
                        message << MultiJson.dump(msg)
         
     | 
| 
      
 96 
     | 
    
         
            +
                      else
         
     | 
| 
      
 97 
     | 
    
         
            +
                        message << massage_message(msg,severity,processid)
         
     | 
| 
      
 98 
     | 
    
         
            +
                      end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       90 
100 
     | 
    
         
             
                      if @input_uri.scheme == 'tcp'
         
     | 
| 
       91 
101 
     | 
    
         
             
                        message << "\r\n"
         
     | 
| 
       92 
102 
     | 
    
         
             
                      end
         
     | 
    
        data/lib/logglier/version.rb
    CHANGED
    
    
    
        data/spec/client/syslog_spec.rb
    CHANGED
    
    | 
         @@ -11,4 +11,32 @@ describe Logglier::Client::Syslog do 
     | 
|
| 
       11 
11 
     | 
    
         
             
                  client.pri("WARN").should == (17 << 3) + 4
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         
             
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              describe '#formatter' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                before do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  UDPSocket.stub(:new).and_return(mock('socket').as_null_object)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  TCPSocket.stub(:new).and_return(mock('Socket').as_null_object)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                let(:client)      { described_class.new(input_url: 'udp://127.0.0.1:514/17') }
         
     | 
| 
      
 22 
     | 
    
         
            +
                let(:json_client) { described_class.new(input_url: 'udp://127.0.0.1:514/17', format: :json) }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                it 'includes the PID in the progname' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                  message = client.formatter.call 'INFO', Time.now, 'banana', 'test message'
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  message.should match(/banana\[#{Process.pid}\]: /)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                context 'when you pass a Hash' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  it 'formats as JSON when the format is JSON' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                    message = json_client.formatter.call 'INFO', Time.now, 'banana', testing_json: true
         
     | 
| 
      
 33 
     | 
    
         
            +
                    message.should match(/: {"testing_json":true}\z/)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  it 'formats as a massaged message when the format is not JSON' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    message = client.formatter.call 'INFO', Time.now, 'banana', testing_json: false
         
     | 
| 
      
 38 
     | 
    
         
            +
                    message.should match(/: testing_json=false\z/)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | 
         @@ -38,21 +38,35 @@ shared_examples_for "a logglier enhanced Logger instance" do 
     | 
|
| 
       38 
38 
     | 
    
         
             
              context "#add" do
         
     | 
| 
       39 
39 
     | 
    
         
             
                context "with a string" do
         
     | 
| 
       40 
40 
     | 
    
         
             
                  it "should send a message via the logdev" do
         
     | 
| 
       41 
     | 
    
         
            -
                    subject.logdev.dev. 
     | 
| 
      
 41 
     | 
    
         
            +
                    if subject.logdev.dev.is_a?(Logglier::Client::Syslog)
         
     | 
| 
      
 42 
     | 
    
         
            +
                      subject.logdev.dev.should_receive(:write).with(/foo/)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    else
         
     | 
| 
      
 44 
     | 
    
         
            +
                      subject.logdev.dev.should_receive(:write).with(/severity=WARN, foo/)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
       42 
47 
     | 
    
         
             
                    subject.add(Logger::WARN) { 'foo' }
         
     | 
| 
       43 
48 
     | 
    
         
             
                  end
         
     | 
| 
       44 
49 
     | 
    
         
             
                end
         
     | 
| 
       45 
50 
     | 
    
         | 
| 
       46 
51 
     | 
    
         
             
                context "with a hash" do
         
     | 
| 
       47 
52 
     | 
    
         
             
                  it "should send a message via the logdev" do
         
     | 
| 
       48 
     | 
    
         
            -
                     
     | 
| 
       49 
     | 
    
         
            -
                     
     | 
| 
       50 
     | 
    
         
            -
                    subject.logdev.dev. 
     | 
| 
      
 53 
     | 
    
         
            +
                    # expect count is the number of times we need to
         
     | 
| 
      
 54 
     | 
    
         
            +
                    # repeat the log message to test all of the possibilities
         
     | 
| 
      
 55 
     | 
    
         
            +
                    if subject.logdev.dev.is_a?(Logglier::Client::Syslog)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      expect_count = 2
         
     | 
| 
      
 57 
     | 
    
         
            +
                    else
         
     | 
| 
      
 58 
     | 
    
         
            +
                      expect_count = 3
         
     | 
| 
      
 59 
     | 
    
         
            +
                      subject.logdev.dev.should_receive(:write).with(/severity=WARN/)
         
     | 
| 
      
 60 
     | 
    
         
            +
                    end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                    expect(subject.logdev.dev).to receive(:write).with(/foo=bar/)
         
     | 
| 
      
 63 
     | 
    
         
            +
                    expect(subject.logdev.dev).to receive(:write).with(/man=pants/)
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       51 
65 
     | 
    
         
             
                    # The following is equiv to:
         
     | 
| 
       52 
66 
     | 
    
         
             
                    # subject.warn :foo => :bar, :man => :pants
         
     | 
| 
       53 
     | 
    
         
            -
                     
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                     
     | 
| 
      
 67 
     | 
    
         
            +
                    expect_count.times do
         
     | 
| 
      
 68 
     | 
    
         
            +
                      subject.add(Logger::WARN) { {:foo => :bar, :man => :pants} }
         
     | 
| 
      
 69 
     | 
    
         
            +
                    end
         
     | 
| 
       56 
70 
     | 
    
         
             
                  end
         
     | 
| 
       57 
71 
     | 
    
         
             
                end
         
     | 
| 
       58 
72 
     | 
    
         
             
              end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: logglier
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.4.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Edward Muller (aka freeformz)
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-12-14 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: multi_json
         
     |