dlogger 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af1bd8fdd7d791b39c4fe3d106a8df1db5ab0f74
4
- data.tar.gz: 94c6a2f737b107d8885a5c3e0a691fbf54e86b7a
3
+ metadata.gz: a66b797653f4bdb8bd82f224a9c5db694a67b935
4
+ data.tar.gz: cbd43d32888668b98b1a1e2f7abb9b03df6208bb
5
5
  SHA512:
6
- metadata.gz: 856eb08a81421676af540cc839491c60b2b10cbdccc977c38ff36ff056d3ead02f70fbecdb71a3a1761e60623a0eefaeb457035e9a6a5f00c3d2978ae7672918
7
- data.tar.gz: 56dca1e86e6a402c54226c49be0a64fea832e260f0474bd32efef966ab901c4fae1860150a2b3f29ba3d11a50d7bd076e00f78d2a098eef7ca58676a82ecbe6f
6
+ metadata.gz: 310fc64c152285818a836014ca4a54ff4eed34f953beab9a3f922d06329d2c4b9185fd42e518c381db63ea944eb604af51d723dd9563d31052abe1a435078faf
7
+ data.tar.gz: 829ce6c67279160ededa757b2befc52693223bd2ccb7fc179421afefe8d08e8073e05f5b5338f23b57923616c577329b066be69b4ee5e8b2c2c2e6c68017c5c1
data/Gemfile CHANGED
@@ -7,6 +7,8 @@ gem 'eventmachine', '~> 1.0.0.rc.1'
7
7
  gem 'em-http-request'
8
8
  gem 'yajl-ruby'
9
9
 
10
+ gem 'syslog_protocol', github: 'newrelic-forks/syslog_protocol'
11
+
10
12
  group(:test) do
11
13
  gem 'rake'
12
14
 
@@ -7,7 +7,7 @@ module DLogger
7
7
  @outputs = []
8
8
 
9
9
  # initialize context
10
- context
10
+ init_context
11
11
  end
12
12
 
13
13
  ##
@@ -110,11 +110,15 @@ module DLogger
110
110
 
111
111
  private
112
112
 
113
+ def init_context
114
+ Thread.current["#{@name}_dlogger_contexts"] = []
115
+ end
116
+
113
117
  ##
114
118
  # Store the context in fiber local variables, each
115
119
  # Thread/Fiber gets its own.
116
120
  def context
117
- Thread.current["#{@name}_dlogger_contexts"] ||= []
121
+ Thread.current["#{@name}_dlogger_contexts"]
118
122
  end
119
123
 
120
124
  ##
@@ -1,5 +1,5 @@
1
1
  gem 'eventmachine'; require 'eventmachine'
2
- gem 'yajl-ruby'; require 'yajl'
2
+ gem 'multi_json'; require 'multi_json'
3
3
 
4
4
  module DLogger
5
5
  module Output
@@ -31,9 +31,9 @@ module DLogger
31
31
 
32
32
  def dispatch(msg, metadata)
33
33
  metadata = metadata.merge(:message => msg)
34
- @socket.send_data( Yajl::Encoder.encode(metadata) + "\n" )
34
+ @socket.send_data( MultiJson.encode(metadata) + "\n" )
35
35
  end
36
36
  end
37
37
 
38
38
  end
39
- end
39
+ end
@@ -0,0 +1,37 @@
1
+ gem 'eventmachine'; require 'eventmachine'
2
+ gem 'multi_json'; require 'multi_json'
3
+ gem 'syslog_protocol'; require 'syslog_protocol'
4
+
5
+ module DLogger
6
+ module Output
7
+
8
+ ##
9
+ # This is not strictly a standard syslog output but it is designed
10
+ # to be used with rsyslog as a pass trhough to send data to elasticsearch
11
+ #
12
+ class Syslog < Base
13
+ def initialize(host, port, bind_address: '0.0.0.0')
14
+ @host = host
15
+ @port = port
16
+
17
+ @socket = EM::open_datagram_socket(bind_address, 0)
18
+ end
19
+
20
+ def dispatch(msg, metadata)
21
+ metadata = metadata.merge(message: msg)
22
+
23
+ p = SyslogProtocol::Packet.new
24
+ p.hostname = "unused"
25
+ p.facility = "kern"
26
+ p.severity = "info"
27
+ p.tag = "app"
28
+ p.content = MultiJson.encode(metadata)
29
+
30
+ @socket.send_datagram(p.to_s, @host, @port)
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
37
+
@@ -1,3 +1,3 @@
1
1
  module Dlogger
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -47,6 +47,21 @@ describe "Logger" do
47
47
 
48
48
  end
49
49
 
50
+ should 'keep pushed context' do
51
+ @logger.expects(:dispatch).with('msg1', id: 43, global: 'A')
52
+ @logger.expects(:dispatch).with('msg2', id: 43, user: 'john', global: 'A')
53
+ @logger.expects(:dispatch).with('msg3', id: 43, global: 'A')
54
+
55
+ @logger.push_context(global: 'A')
56
+ @logger.log('msg1', id: 43)
57
+
58
+ @logger.with_context(user: ->{ "john" } ) do
59
+ @logger.log('msg2', id: 43)
60
+ end
61
+
62
+ @logger.log('msg3', id: 43)
63
+ end
64
+
50
65
  end
51
66
 
52
67
  describe 'with extension context' do
@@ -0,0 +1,39 @@
1
+ require_relative "../../../common"
2
+
3
+ require 'dlogger/outputs/em/syslog'
4
+
5
+ $n = 0
6
+
7
+ describe "Syslog Output" do
8
+ before do
9
+ @port = 4000 + ($n += 1)
10
+ @received_data = ""
11
+
12
+ tmp = @received_data
13
+
14
+ @handler_class = Class.new(EM::Connection) do
15
+ define_method(:receive_data) do |data|
16
+ tmp << data
17
+ end
18
+ end
19
+
20
+
21
+ # @server = EM::start_server('127.0.0.1', @port, @handler_class)
22
+ @server = EM::open_datagram_socket('127.0.0.1', @port, @handler_class)
23
+
24
+ @logger = DLogger::Output::Syslog.new('127.0.0.1', @port)
25
+ end
26
+
27
+ should 'send message to syslog via UDP' do
28
+ t = "Apr 15 16:46:32"
29
+
30
+ freeze_time(Time.parse(t)) do
31
+ @logger.dispatch('a log message', {:data => "something", :n => 21})
32
+
33
+ wait(0.1) do
34
+ @received_data.should == %{<6>#{t} unused app: {"data":"something","n":21,"message":"a log message"}}
35
+ end
36
+ end
37
+ end
38
+
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dlogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Ammous
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Advanced logger allowing you to include metadata with your messages
14
14
  email:
@@ -17,7 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
20
+ - ".gitignore"
21
21
  - ChangeLog
22
22
  - Gemfile
23
23
  - Guardfile
@@ -39,6 +39,7 @@ files:
39
39
  - lib/dlogger/outputs/base.rb
40
40
  - lib/dlogger/outputs/em/logstash.rb
41
41
  - lib/dlogger/outputs/em/splunkstorm.rb
42
+ - lib/dlogger/outputs/em/syslog.rb
42
43
  - lib/dlogger/outputs/stdlib_logger.rb
43
44
  - lib/dlogger/outputs/stdout.rb
44
45
  - lib/dlogger/version.rb
@@ -47,6 +48,7 @@ files:
47
48
  - specs/lib/logger_spec.rb
48
49
  - specs/lib/outputs/em/logstash_spec.rb
49
50
  - specs/lib/outputs/em/splunkstorm_spec.rb
51
+ - specs/lib/outputs/em/syslog_spec.rb
50
52
  - specs/lib/outputs/stdlib_logger_spec.rb
51
53
  - specs/lib/outputs/stdout_spec.rb
52
54
  homepage: ''
@@ -58,17 +60,17 @@ require_paths:
58
60
  - lib
59
61
  required_ruby_version: !ruby/object:Gem::Requirement
60
62
  requirements:
61
- - - '>='
63
+ - - ">="
62
64
  - !ruby/object:Gem::Version
63
65
  version: '0'
64
66
  required_rubygems_version: !ruby/object:Gem::Requirement
65
67
  requirements:
66
- - - '>='
68
+ - - ">="
67
69
  - !ruby/object:Gem::Version
68
70
  version: '0'
69
71
  requirements: []
70
72
  rubyforge_project:
71
- rubygems_version: 2.0.3
73
+ rubygems_version: 2.2.2
72
74
  signing_key:
73
75
  specification_version: 4
74
76
  summary: 'Dynamic logger: add a context to your log messages'