logplex 0.0.1.pre → 0.0.1.pre.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,18 +2,19 @@
2
2
 
3
3
  Publish and Consume Logplex messages
4
4
 
5
- Logplex is the Heroku log router, and can be found [here](https://github.com/heroku/logplex).
5
+ Logplex is the Heroku log router, and can be found
6
+ [here](https://github.com/heroku/logplex).
6
7
 
7
8
  ### Publishing messages
8
9
 
9
10
  ```ruby
10
11
  publisher = Logplex::Publisher.new(logplex_token, logplex_url)
11
- publisher.publish("This is a log entry", process: 'worker.2',
12
- host: 'some-host')
12
+ publisher.publish("There's a lady who's sure, all that glitters is gold",
13
+ process: 'worker.2', host: 'some-host')
13
14
  ```
14
15
 
15
- Passing an array of messages to the `#publish` method will publish them all in one request,
16
- so some latency optimization is possible:
16
+ Passing an array of messages to the `#publish` method will publish them all in
17
+ one request, so some latency optimization is possible:
17
18
 
18
19
  ```ruby
19
20
  publisher.publish [ "And as we wind on down the road",
@@ -22,6 +23,14 @@ publisher.publish [ "And as we wind on down the road",
22
23
  "Who shines white light and wants to show"]
23
24
  ```
24
25
 
26
+ The message can also be passed in the form of a Hash, in which case it is
27
+ formatted as machine readble key/value pairs suitable for metrics collection,
28
+ eg: [log2viz](https://blog.heroku.com/archives/2013/3/19/log2viz)
29
+
30
+ ```ruby
31
+ publisher.publish { vocals: 'Robert Plant', guitar: 'Jimmy Page' }
32
+ # produces the message: vocals='Robert Plant' guitar='Jimmy Page'
33
+ ```
25
34
  ### Consumnig messages
26
35
 
27
36
  TBD
@@ -38,9 +47,8 @@ Logplex.configure do |config|
38
47
  end
39
48
  ```
40
49
 
41
- In the example above, it is now not not necessary to
42
- specify a logplex URL, process or host when getting
43
- a hold of a publisher and publishing messages:
50
+ In the example above, it is now not not necessary to specify a logplex URL,
51
+ process or host when getting a hold of a publisher and publishing messages:
44
52
 
45
53
  ```ruby
46
54
  publisher = Logplex::Publisher.new(logplex_token)
@@ -49,4 +57,5 @@ publisher.publish "And she's buying a stairway to heaven"
49
57
 
50
58
  ### License
51
59
 
52
- Copyright (c) Harold Giménez. Released under the terms of the MIT License found in the LICENSE file.
60
+ Copyright (c) Harold Giménez. Released under the terms of the MIT License found
61
+ in the LICENSE file.
@@ -6,6 +6,7 @@ module Logplex
6
6
 
7
7
  def initialize
8
8
  @logplex_url = 'https://east.logplex.io'
9
+ @host = 'localhost'
9
10
  end
10
11
  end
11
12
 
@@ -22,7 +22,7 @@ module Logplex
22
22
  end
23
23
 
24
24
  def syslog_frame
25
- temp = "#{FACILITY_AND_PRIORITY} #{formatted_time} #{@host} #{@token} #{@process} #{@message_id} #{FIELD_DISABLED} #{@message}"
25
+ temp = "#{FACILITY_AND_PRIORITY} #{formatted_time} #{@host} #{@token} #{@process} #{@message_id} #{FIELD_DISABLED} #{formatted_message}"
26
26
  length = temp.length
27
27
  "#{length} #{temp}"
28
28
  end
@@ -43,5 +43,16 @@ module Logplex
43
43
  @time.to_datetime.rfc3339
44
44
  end
45
45
  end
46
+
47
+ def formatted_message
48
+ if @message.kind_of?(Hash)
49
+ @message.inject([]) do |res, (key, value)|
50
+ res << %{#{key}="#{value}"}
51
+ end.join(' ')
52
+ else
53
+ @message
54
+ end
55
+ end
56
+
46
57
  end
47
58
  end
@@ -1,3 +1,3 @@
1
1
  module Logplex
2
- VERSION = "0.0.1.pre"
2
+ VERSION = "0.0.1.pre.2"
3
3
  end
@@ -34,6 +34,11 @@ describe Logplex::Message do
34
34
  end
35
35
 
36
36
  it 'is invalid with no process or host' do
37
+ Logplex.configure do |conf|
38
+ conf.host = nil
39
+ conf.process = nil
40
+ end
41
+
37
42
  message = Logplex::Message.new("a message", token: 't.some-token')
38
43
  message.validate
39
44
 
@@ -41,4 +46,18 @@ describe Logplex::Message do
41
46
  expect(message.errors[:process]).to eq ["can't be nil"]
42
47
  expect(message.errors[:host]).to eq ["can't be nil"]
43
48
  end
49
+
50
+ it 'formats logs as key/values when given a hash' do
51
+ message = Logplex::Message.new(
52
+ { vocals: 'Robert Plant', guitar: 'Jimmy Page' },
53
+ token: 't.some-token',
54
+ process: 'proc',
55
+ host: 'host',
56
+ time: DateTime.parse("1980-08-23 05:31 00:00")
57
+ )
58
+
59
+ expect(message.syslog_frame).to eq(
60
+ %{101 <134>1 1980-08-23T05:31:00+00:00 host t.some-token proc - - vocals="Robert Plant" guitar="Jimmy Page"}
61
+ )
62
+ end
44
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logplex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1.pre.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: valcro
16
- requirement: &70148113247780 !ruby/object:Gem::Requirement
16
+ requirement: &70106294975600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70148113247780
24
+ version_requirements: *70106294975600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &70148113247240 !ruby/object:Gem::Requirement
27
+ requirement: &70106294975040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70148113247240
35
+ version_requirements: *70106294975040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70148113246560 !ruby/object:Gem::Requirement
38
+ requirement: &70106294974360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70148113246560
46
+ version_requirements: *70106294974360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sham_rack
49
- requirement: &70148113245700 !ruby/object:Gem::Requirement
49
+ requirement: &70106294973520 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70148113245700
57
+ version_requirements: *70106294973520
58
58
  description: Publish and Consume Logplex messages
59
59
  email:
60
60
  - harold.gimenez@gmail.com