dohlog 0.1.3 → 0.1.4

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.
@@ -0,0 +1,39 @@
1
+ require 'net/smtp'
2
+
3
+ module DohLog
4
+
5
+ class EmailAcceptor
6
+ # required config fields are :from, :to, :server
7
+ def initialize(config, &get_details)
8
+ @config = config
9
+ @get_details = get_details
10
+ @msg_start = "From:#{config[:from]}\nTo:#{config[:to].join(', ')}\nContent-Type: text/plain\nSubject:"
11
+ end
12
+
13
+ def add(event)
14
+ msg = "#{@msg_start}#{event.severity_text}: #{event.msg}\n\n#{event.summary}\n#{details_text}\n#{event.exception_text}"
15
+ Net::SMTP.start(@config[:server]) do |smtp|
16
+ begin
17
+ smtp.send_message(msg, @config[:from], @config[:to])
18
+ rescue => excpt
19
+ puts "dohlog EmailAcceptor send failed: #{excpt}"
20
+ end
21
+ end
22
+ end
23
+
24
+ def shutdown
25
+ end
26
+
27
+ private
28
+ def details_text
29
+ map = @get_details.call
30
+ lines = []
31
+ map.each_pair do |key, value|
32
+ lines << "#{key}: #{value}"
33
+ end
34
+ lines.join("\n")
35
+ end
36
+
37
+ end
38
+
39
+ end
data/lib/doh/log/event.rb CHANGED
@@ -23,7 +23,9 @@ class Event
23
23
  end
24
24
 
25
25
  def exception_text
26
- if @exception then "#{@exception.class} => #{@exception.message}" else '' end
26
+ return '' unless @exception
27
+ stack = @exception.backtrace.collect { |elem| "=> #{elem}" }.join("\n")
28
+ "=> exception: #{@exception.class} - #{@exception.message}\n=> stack:\n#{stack}"
27
29
  end
28
30
 
29
31
  def call_stack
@@ -0,0 +1,20 @@
1
+ module DohLog
2
+
3
+ class FilterAcceptor
4
+ def initialize(acceptor, &pred)
5
+ @acceptor = acceptor
6
+ @pred = pred
7
+ end
8
+
9
+ def add(event)
10
+ if @pred.call(event)
11
+ @acceptor.add(event)
12
+ end
13
+ end
14
+
15
+ def shutdown
16
+ @acceptor.shutdown
17
+ end
18
+ end
19
+
20
+ end
@@ -9,12 +9,7 @@ class StreamAcceptor
9
9
  end
10
10
 
11
11
  def add(event)
12
- @ios.puts(event.summary)
13
- if event.severity >= DohLog::ERROR
14
- @ios.puts("=> exception: #{event.exception_text}")
15
- @ios.puts("=> stack:")
16
- event.call_stack.each { |elem| @ios.puts("=> #{elem}") }
17
- end
12
+ @ios.puts("#{event.summary}\n#{event.exception_text}")
18
13
  @ios.fsync if @flush
19
14
  end
20
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-03 00:00:00.000000000 Z
13
+ date: 2012-05-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dohutil
@@ -37,7 +37,9 @@ extensions: []
37
37
  extra_rdoc_files:
38
38
  - MIT-LICENSE
39
39
  files:
40
+ - lib/doh/log/email_acceptor.rb
40
41
  - lib/doh/log/event.rb
42
+ - lib/doh/log/filter_acceptor.rb
41
43
  - lib/doh/log/integrate.rb
42
44
  - lib/doh/log/interface.rb
43
45
  - lib/doh/log/memory_acceptor.rb
@@ -71,6 +73,6 @@ rubyforge_project:
71
73
  rubygems_version: 1.8.24
72
74
  signing_key:
73
75
  specification_version: 3
74
- summary: zeromq powered logging framework
76
+ summary: zeromq powered logging framework (eventually)
75
77
  test_files: []
76
78
  has_rdoc: