logglier 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Edward Muller
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -33,20 +33,57 @@ Input URLs
33
33
  Logglier.new('https://logs.loggly.com/inputs/<id>')
34
34
 
35
35
  The id is provided by loggly, look at the input's details page
36
+ To make sure the http client doesn't block too long read_timeout and
37
+ open_timeout are set to 2 seconds by default. This can be overridden
38
+ like so:
36
39
 
37
- ### Syslog UDP Inputs
40
+ Logglier.new(:input_url => 'https://logs.loggle.com/inputs/<id>',
41
+ :read_timeout => <#>,
42
+ :open_timeout => <#> )
38
43
 
39
- Logglier.new('udp://<hostname>:<port>/<facility>')
44
+ ### Syslog TCP/UDP Inputs
45
+
46
+ Logglier.new('[udp|tcp]://<hostname>:<port>/<facility>')
40
47
 
41
48
  The facility is optional and defaults to 16 (local0) if none is
42
49
  specified. Facilities are just integers from 0 to 23, see <http://www.faqs.org/rfcs/rfc3164.html>
43
50
 
44
51
 
52
+ Logging
53
+ -------
54
+
55
+ Logglier.new returns a ruby Logger object, so take a look at:
56
+
57
+ http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/
58
+
59
+ The Logger's logdev has some special format handling though.
60
+
61
+ ### Logging a string
62
+
63
+ log.warn "test"
64
+
65
+ Will produce the following log message in Loggly:
66
+
67
+ "<Date> severity=WARN, test"
68
+
69
+ ### Logging a Hash
70
+
71
+ log.warn :boom => :box, :bar => :soap
72
+
73
+ Will produce the following log message in Loggly:
74
+
75
+ "<Date> severity=WARN, boom=box, bar=soap"
76
+
77
+ Bugs
78
+ -----
79
+
80
+ https://github.com/freeformz/logglier/issues
81
+
82
+ Pull requests welcome
83
+
45
84
  TODO
46
85
  -----
47
86
 
48
- * key=value Loggly stuff.
49
87
  * Alternative https implementations (Typheous, Excon, etc). May be
50
88
  faster?
51
- * Option to use Syslog TCP inputs. Possibly faster than the https inputs.
52
89
  * Do logging in a seperate thread. Is this useful? Too complex?
@@ -27,12 +27,31 @@ module Logglier
27
27
 
28
28
  module InstanceMethods
29
29
 
30
+ def masherize_key(prefix,key)
31
+ [prefix,key.to_s].compact.join('.')
32
+ end
33
+
34
+ def masher(hash, prefix=nil)
35
+ hash.map do |v|
36
+ if v[1].is_a?(Hash)
37
+ masher(v[1],masherize_key(prefix,v[0]))
38
+ else
39
+ "#{masherize_key(prefix,v[0])}=" << case v[1]
40
+ when Symbol
41
+ v[1].to_s
42
+ else
43
+ v[1].inspect
44
+ end
45
+ end
46
+ end.join(", ")
47
+ end
48
+
30
49
  def massage_message(incoming_message, severity)
31
50
  outgoing_message = ""
32
51
  outgoing_message << "severity=#{severity}, "
33
52
  case incoming_message
34
53
  when Hash
35
- outgoing_message << incoming_message.map { |v| "#{v[0]}=#{v[1]}" }.join(", ")
54
+ outgoing_message << masher(incoming_message)
36
55
  when String
37
56
  outgoing_message << incoming_message
38
57
  else
@@ -1,3 +1,3 @@
1
1
  module Logglier
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -14,7 +14,7 @@ EOD
14
14
  s.email =
15
15
  s.homepage = "http://loggly.com"
16
16
 
17
- s.files = %w{ README.md Gemfile logglier.gemspec Rakefile } + Dir["#{dir}/lib/**/*.rb"]
17
+ s.files = %w{ README.md Gemfile LICENSE logglier.gemspec Rakefile } + Dir["#{dir}/lib/**/*.rb"]
18
18
  s.require_paths = ["lib"]
19
19
  s.test_files = Dir["#{dir}/spec/**/*.rb"]
20
20
 
@@ -64,11 +64,47 @@ describe Logglier::Client do
64
64
 
65
65
  context "HTTPS" do
66
66
  context "#write" do
67
- it "should post a message" do
68
- log = Logglier::Client.new('https://localhost')
69
- log.http.stub(:request_post)
70
- log.http.should_receive(:request_post).with('','msg')
71
- log.write('msg')
67
+ context "with a simple text message" do
68
+ it "should post a message" do
69
+ log = Logglier::Client.new('https://localhost')
70
+ log.http.stub(:request_post)
71
+ log.http.should_receive(:request_post).with('','msg')
72
+ log.write('msg')
73
+ end
74
+ end
75
+ end
76
+
77
+ context "message formatting methods" do
78
+ subject { Logglier::Client.new('https://localhost') }
79
+
80
+ it "should mash out hashes" do
81
+ message = subject.massage_message({:foo => :bar},"WARN")
82
+ message.should =~ /^severity=WARN,/
83
+ message.should =~ /foo=bar/
84
+ end
85
+
86
+ it "should mash out nested hashes" do
87
+ message = subject.massage_message({:foo => :bar, :bazzle => { :bom => :bastic } }, "WARN")
88
+ message.should =~ /^severity=WARN,/
89
+ message.should =~ /foo=bar/
90
+ message.should =~ /bazzle\.bom=bastic/
91
+ end
92
+
93
+ it "should mash out deeply nested hashes" do
94
+ message = subject.massage_message({:foo => :bar, :bazzle => { :bom => :bastic, :totally => { :freaking => :funny } } }, "WARN")
95
+ message.should =~ /^severity=WARN,/
96
+ message.should =~ /foo=bar/
97
+ message.should =~ /bazzle\.bom=bastic/
98
+ message.should =~ /bazzle\.totally\.freaking=funny/
99
+ end
100
+
101
+ it "should mash out deeply nested hashes, with an array" do
102
+ message = subject.massage_message({:foo => :bar, :taste => ["this","sauce"], :bazzle => { :bom => :bastic, :totally => { :freaking => :funny } } }, "WARN")
103
+ message.should =~ /^severity=WARN,/
104
+ message.should =~ /foo=bar/
105
+ message.should =~ /taste=\["this", "sauce"\]/
106
+ message.should =~ /bazzle\.bom=bastic/
107
+ message.should =~ /bazzle\.totally\.freaking=funny/
72
108
  end
73
109
  end
74
110
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logglier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Edward Muller (aka freeformz)
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - README.md
63
63
  - Gemfile
64
+ - LICENSE
64
65
  - logglier.gemspec
65
66
  - Rakefile
66
67
  - ./lib/logglier.rb