releaseable 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/releaseable/extensions.rb +54 -27
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.6
@@ -2,14 +2,34 @@ require 'logger'
2
2
  require 'logglier'
3
3
  require 'java'
4
4
 
5
+ # Selectively silence verbose JRuby warnings
6
+ def suppress_all_warnings
7
+ old_verbose = $VERBOSE
8
+ begin
9
+ $VERBOSE = nil
10
+ yield if block_given?
11
+ ensure
12
+ # always re-set to old value, even if block raises an exception
13
+ $VERBOSE = old_verbose
14
+ end
15
+ end
16
+
5
17
  # Avoid OpenSSL failures
6
- OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
18
+ suppress_all_warnings do
19
+ OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
20
+ end
7
21
 
8
22
  # Logger extensions
9
23
  class Logger
10
24
 
25
+ INPUTS = {:default => 'c568432d-8f50-4b12-9322-5f6ffda7883b',
26
+ :opts => 'b9a22025-b148-4dfe-8355-ce5dba40b6a2',
27
+ :json => '62a8ef41-fd80-460f-a6f7-e45f232dd1d8',
28
+ :aux => '207f124e-9de6-434f-b100-af1ac3585089', }
29
+
11
30
  attr_accessor :config
12
31
 
32
+ # Alarm sound to get my attention
13
33
  def self.sound_alarm beeps = 3
14
34
  beeps.times do
15
35
  java.awt.Toolkit.getDefaultToolkit.beep
@@ -17,33 +37,57 @@ class Logger
17
37
  end
18
38
  end
19
39
 
40
+ # Alarm sound on Logger instance
20
41
  def sound_alarm beeps = @config[:beeps]
21
42
  self.class.sound_alarm beeps
22
43
  end
23
44
 
24
45
  alias old_fatal fatal
25
46
 
47
+ # Extended handler for fatal errors
26
48
  def fatal *args
27
49
  if @config && @config[:fatal]
28
50
  entry = args.first
29
51
  case entry
30
52
  when Exception
31
- @config[:fatal].fatal "#{entry.class}: '#{entry.message}' at #{caller.join(', ')}"
53
+ @config[:fatal].fatal :tag => @config[:tag],
54
+ :error => entry.class,
55
+ :msg => entry.message,
56
+ :backtrace => entry.backtrace.join(', ')
32
57
  else
33
- @config[:fatal].info *args
58
+ @config[:fatal].info :tag => @config[:tag],
59
+ :msg => "#{args.join(', ')}"
60
+ old_fatal *args
34
61
  end
62
+ else
63
+ old_fatal *args
35
64
  end
36
- old_fatal *args
37
65
  end
38
66
 
39
- def configure config, &formatter
40
- @config = config.dup
67
+ # Extended configuration for Logger
68
+ def configure config={}, &formatter
69
+ @config = (config[:log] || config).dup
41
70
  @config[:beeps] ||= 0
42
71
  @config[:time_format] ||= @config[:time] || '%M:%S.%N'
43
- @config[:input] ||= 'b9a22025-b148-4dfe-8355-ce5dba40b6a2' #non-default
44
- @config[:domain] ||= 'logs.loggly.com'
45
- unless @config[:ignore]
46
- @config[:fatal] ||= Logglier.new "https://#{@config[:domain]}/inputs/#{@config[:input]}"
72
+
73
+ unless @config[:ignore] # fatal errors
74
+ @config[:progname] = config[:progname] || ''
75
+ @config[:tag] = config[:tag] || config[:name] || config[:connection] && config[:env] ?
76
+ "#{config[:env]}#{config[:connection][:client_id]}" : "Tag#{rand(10000)}"
77
+ input = case @config[:input]
78
+ when Symbol
79
+ INPUTS[@config[:input]]
80
+ when nil
81
+ INPUTS[:opts]
82
+ else
83
+ @config[:input]
84
+ end
85
+ domain ||= @config[:domain] || 'https://logs.loggly.com'
86
+ @config[:fatal] ||= Logglier.new "#{domain}/inputs/#{input}",
87
+ :read_timeout => 3,
88
+ :open_timeout => 3,
89
+ :threaded => true,
90
+ :format => :json
47
91
  end
48
92
 
49
93
  self.level = @config[:level] || Logger::INFO
@@ -52,20 +96,3 @@ class Logger
52
96
  end
53
97
  end
54
98
  end
55
-
56
- # Object#raise extensions
57
-
58
- alias old_raise raise
59
-
60
- # Sound alarm before raising error
61
- def raise error
62
- ex = error.kind_of?(String) ? RuntimeError.new(error) : error.exception
63
-
64
- if defined?(log) && log.config
65
- log.sound_alarm
66
- log.fatal ex
67
- else
68
- Logger.sound_alarm
69
- end
70
- old_raise ex #, ex.message, caller #ex.backtrace
71
- end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: releaseable
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - arvicco
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-28 00:00:00 Z
13
+ date: 2012-01-29 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler